Forum Moderators: coopster

Message Too Old, No Replies

Help With Redirect On Referer

Got the code just need somethng added

         

ivaansdad

5:01 pm on Mar 18, 2009 (gmt 0)

10+ Year Member



Hey, I'm pretty new at using php on my sites. I'm having fun with it though and like all the net things it does for me.

Well I was trying to redirect traffic from a certain referer and was going to use this:

<?
if ($HTTP_REFERER= 'www.somedomain.com')
{
header ("Location: somepage.html");
}
?>

Just needed to know how do I get the traffic that is not form the referer to go to another page. Can I just repeat the above coding but leave the variable blank?

In other words is this correct?

<?
if ($HTTP_REFERER= 'www.somedomain.com')
{
header ("Location: somepage.html");
}
if ($HTTP_REFERER= '')
{
header ("Location: somepage.html");
}
?>

or this?

<?
if ($HTTP_REFERER= 'www.somedomain.com')
{
header ("Location: somepage.html");
}
?>
<?
if ($HTTP_REFERER= '')
{
header ("Location: somepage.html");
}
?>

If someone can get me going in the right direction or if I need another "if" statement please let me know.

coopster

5:43 pm on Mar 18, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, ivaansdad.

You can use the else [php.net] part of the if [php.net] control structure.

By the way, a word of caution when relying on REFERER -- web browsers may not send the referer along and it cannot be trusted. A quick search over the forums will turn up plenty of reading.

Also, when using a redirect header as you are, you should really be using the full url and not just a relative path. More information on the PHP manual page for header [php.net].

ivaansdad

6:47 pm on Mar 18, 2009 (gmt 0)

10+ Year Member



Hey thanks alot I really appreciate the info.