I'm trying to figure out how to do this in PHP: if (visitorreferrerurl != from currentdomain) { some echoed html code here } Code (markup): Don't know what the php command to check that stuff is. Anyone know offhand? Note - this will be going into a wordpress theme on all pages, so I'm not sure if all PHP commands can be run through <?php ?> in there or not.
try this code, <?php $visitorreferrerurl = $_SERVER['HTTP_HOST']; $currentdomain = 'www.yourdomain.com'; if($visitorreferrerurl != $currentdomain) { echo 'error'; } ?> Code (markup):
Actually it would be... if(stristr($_SERVER['HTTP_REFERER'], "yoursite.com")){ // from your site }else{ // not from here }
DO NOT USE THIS. It is not proper coding logic. Stristr returns a string, should not be used this way (checking for existance). Here: if(strpos($_SERVER['HTTP_REFERER'], "yoursite.com")===false){ // Not from your site }else{ // from here } PHP:
if(preg_match("/domain.com/i",$_SERVER['HTTP_REFERER'])) { // my site in the referrer } else { // other site or blank referrer } PHP:
stristr returns a string OR false if needle is not found. There is nothing illogical about checking if stristr has returned false.
I don't mean to resurrect a dead topic, but yes there is something illogical about USING stristr for check a string's presence in another string. It returns a string, which means PHP's interpreter must search the string, then splice the string...Instead, using strpos will result in you being able to find the string AND just return a number...which is all that is needed. Using extra code, is pointless and on large sites can make the difference between downtime and uptime... strpos can be used as follows: // Checking for string existance if(strpos('abc','f')===false) //Since 0 in this case is not a false result we check for an absolute false. // DO STUFF else // WAS FOUND, DO STUFF PHP:
yep, its $_SERVER['HTTP_REFERER'] an easy way to do it .. turn the prior website they came from (HTTP_REFERER) into a variable. $website_camefrom = $_SERVER['HTTP_REFERER']; // then do the logic for it. if($website_camefrom == $website_youwant){ //example. echo "You came from the website i wanted you to come from!"; } else { echo "you came from a website i dont give a crap about dork!"; } in the code to un in the logic ..you can do whatever you want instead of echoing stuff. Turn your Referr and your websites you want to check it by ..into PHP simple variables. thats a good way to keep it from becoming confusing if you look at it 5 years later and wonder what the heck it is.