469,926 Members | 1,824 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

Sending people to specific pages that are coming from specific pages...


I want to show some specific pages to people that comes to my site from
specific urls, I know the variable $_SERVER['HTTP_REFERER'] will be
used but how?

For ex if the visitor comes from a site that is like:


I want to send this person a specific.php . I used below code but not


if($_SERVER['HTTP_REFERER'] == "www.cominghost.com" ||
$_SERVER['HTTP_REFERER'] == "cominghost.com" ||
$_SERVER['HTTP_REFERER'] == "www2.cominghost.com"){

// Specific page html goes here

header("Location: index.php");

This code not worked for some cases like if the visitor comes from
http://www.cominghost.com/account/targeturl.php or
http://cominghost.com/account/targeturl.php Ok I know the if statement
not working but How???


Dec 5 '05 #1
2 1354
First of all, don't count on the HTTP_REFERER (sic) variable to be
accurate. It's up to the browser to set it, so it can always be
incorrect or not there.

Having said that, what you want is strpos():


Better yet, try his cousing stripos() for a case insensitive match. So
something like this:

if(stripos($_SERVER['HTTP_REFERER'], 'cominghost.com') !== false) {
//Special code goes here
else {
//Normal code goes here

Of course this isn't totally correct because
http://www.foo.com/bar/cominghost.html would be accepted. If it's
really that important, you can use a regular expression instead.

Dec 6 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

38 posts views Thread by Anthony Baxter | last post: by
9 posts views Thread by MNQ | last post: by
1 post views Thread by festivalman | last post: by
7 posts views Thread by tshad | last post: by
19 posts views Thread by Charles Law | last post: by
5 posts views Thread by Sebzzz | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.