Jump to content

Newbie Q: If string = this or this then...


SannaJ

Recommended Posts

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?  :shy:

 

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

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 ?
}

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.