SannaJ Posted August 10, 2011 Share Posted August 10, 2011 I have this bit of code. If the website visitor doesn't have a referer then the msg "Hello my friend" is shown. But I also would like to display the same msg if the visitors got the word "linkportal" in the refererURL. Can anyone please help me out here? My code so far: $referer = $_SERVER['HTTP_REFERER']; // Getting the referer $$referer = strtolower($$referer); // Make string to lowercase so we can search for "linkportal". if($referer == "") // How to check for blank referer and "linkportal" here? { echo "Hello my friend!"; } Link to comment https://forums.phpfreaks.com/topic/244406-newbie-q-if-string-this-or-this-then/ Share on other sites More sharing options...
Morg. Posted August 10, 2011 Share Posted August 10, 2011 Just learn regex today A bit hard to start but so useful in the end $hello_my_friend_valid_referer="linkportal|^$|etc."; $t=preg_match("/($hello_my_friend_valid_referer)/i",$_SERVER['HTTP_REFERER']); if($t==false || $t==0){ // woot no match, this should be good ? }else{ // woot match, this should be good ? } Link to comment https://forums.phpfreaks.com/topic/244406-newbie-q-if-string-this-or-this-then/#findComment-1255290 Share on other sites More sharing options...
Alex Posted August 10, 2011 Share Posted August 10, 2011 Something like.. $referer = $_SERVER['HTTP_REFERER']; if(empty($referer) || strpos($referer, 'linkportal') !== false) { echo "Hello my friend!"; } empty strpos Link to comment https://forums.phpfreaks.com/topic/244406-newbie-q-if-string-this-or-this-then/#findComment-1255292 Share on other sites More sharing options...
SannaJ Posted August 10, 2011 Author Share Posted August 10, 2011 Thank you both!!! Link to comment https://forums.phpfreaks.com/topic/244406-newbie-q-if-string-this-or-this-then/#findComment-1255299 Share on other sites More sharing options...
SannaJ Posted August 10, 2011 Author Share Posted August 10, 2011 By the way, why doesn't this work: $product = $_GET['product']; $referer = $_SERVER['HTTP_REFERER']; if(empty($product)) { echo "<html><head>"; echo "<meta http-equiv=refresh content=0;url=http://errorurl.com>"; echo "</head></html>"; } If I surf to www.myurl.com/script.php there is no product set and it should send me to the errorurl but it doesn't. Link to comment https://forums.phpfreaks.com/topic/244406-newbie-q-if-string-this-or-this-then/#findComment-1255347 Share on other sites More sharing options...
SannaJ Posted August 10, 2011 Author Share Posted August 10, 2011 Hmmm... Maybe $products isn't 100% empty when trying to get the data with GET? Link to comment https://forums.phpfreaks.com/topic/244406-newbie-q-if-string-this-or-this-then/#findComment-1255477 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.