Jump to content

how do say "if x!=y or if x!=z then echo"?


markfresh

Recommended Posts

Hi

 

I apologise if this is basic but I have been looking around to see if I can find a solution. . I would like a message to appear if someone has arrived at my site not using the main URL but via one of the redirects I have in place. Now the following works

 

<?php

$mainurl = ($_SERVER['HTTP_HOST']);

$main = "www.mywebsite.co.uk";

if ($mainurl!=$main) {

echo "Hi, the main website is www.mywebsite.co.uk, you have come via ".$_SERVER['HTTP_HOST'];

}

?>

 

but how do I say if the main url does not equal "www.mywebsite.co.uk" or "mywebsite.co.uk" then echo?  I would have thought that

 

<?php

$mainurl = ($_SERVER['HTTP_HOST']);

$main = "www.mywebsite.co.uk";

$main2 = "mywebsite.co.uk";

if ($mainurl!=$main || $mainurl!=$main2) {

echo "Hi, the main website is www.mywebsite.co.uk, you have come via ".$_SERVER['HTTP_HOST'];

}

?>

 

but that doesn't seem to work, any help appreciated

 

thanks

 

Mark

 

Link to comment
Share on other sites

Maybe try switching them around (same thing... but just a thought):

 

if ($main != $mainurl || $main2 != $mainurl) {
echo "Hi, the main website is www.mywebsite.co.uk, you have come via ".$_SERVER['HTTP_HOST'];
}

 

Also, you may need to put "http://" in your URLs.. try echoing $mainurl and see what it outputs

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.