need help with HTTP_REFERER and redirection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Syntax
Forum Newbie
Posts: 2
Joined: Tue Nov 04, 2003 3:06 pm

need help with HTTP_REFERER and redirection

Post by Syntax »

OKay my problem is this.
i need for ppl who come from a domain to be redirected to a certain page

maybe this explenation is better


user comes to my page from DomainBAD he is supposed to be redirected to PAGE.BAD

user comes from any other site user gets the normal page.

Code: Select all

<?php
if ($HTTP_REFERER == "http://domain.BAD/*") 
&#123;  
header("location:http://domain.com/pageBAD.php"); 
&#125; //check for referer success 
else &#123; 

 &#125; //continiue..
?>
Thats what i have so far.
i need it to check the whole domain not just pages.
right now http://www.domain.BAD/page.html get the normal page
i can't keep adding pages that's too much job.

so how can i `redirect all from domain.BAD ??
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

You might want to consider using something using;
http://se.php.net/manual/en/function.isset.php
http://se.php.net/manual/en/function.strstr.php

Code: Select all

<?php
if (isset($_SERVER['HTTP_REFERER'])) { // is it set at all?
    if (strstr($_SERVER['HTTP_REFERER'],'.disney.')) { // match finding
        // .disney. found in referer.
    } else {
        // .disney. not found in referer.
    }
} else {
 // referer is not set, act upon that...
}
?>
strstr is not 100% proof that it's actually the domain found, but closeby. http://www.disney.com/foo.php is in the above just as true as http://www.example.com/a.disney.page.html.
Syntax
Forum Newbie
Posts: 2
Joined: Tue Nov 04, 2003 3:06 pm

Post by Syntax »

Thanks that worked!
Thanks a bunch!
Post Reply