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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.