homepage Welcome to WebmasterWorld Guest from 184.72.91.94
register, login, search, subscribe, help, library, PubCon, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library : Charter : Moderators: coopster & eelixduppy & jatar k

PHP Server Side Scripting Forum

    
Detect referer and write HTML if not internal
Adam_C




msg:1315665
 2:06 pm on Nov 17, 2005 (gmt 0)

Would anyone have a bit of PHP script handy for this:

1. Detect the referrering URL
2. If referrer is internal (from same domain) or the is no referrer do nothing

otherwise

write a line of HTML

 

Receptional Andy




msg:1315666
 3:27 pm on Nov 17, 2005 (gmt 0)

Hi Adam,

That's pretty straightforward. The visitors referrer (unless they block/disable it) is contained in the $_SERVER[HTTP_REFERER] server variable [php.net]. You can search this for your domain name using a php string function such as strpos [php.net]:


<?
// check for occurance of example.com in the referrer. strpos wil return 0 if it isn't found
if (strpos("example.com",$_SERVER[HTTP_REFERER])==0) {
echo "External or no referrer";
}
else {
echo "Internal referrer";
}
?>

Adam_C




msg:1315667
 3:29 pm on Nov 17, 2005 (gmt 0)

Cheers Andy

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
WebmasterWorld ® and PubCon ® are a Registered Trademarks of Pubcon Inc.
© Pubcon Inc. 1996-2012 all rights reserved