markfresh Posted November 20, 2007 Share Posted November 20, 2007 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 Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted November 20, 2007 Share Posted November 20, 2007 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 Quote Link to comment Share on other sites More sharing options...
Karl33to Posted November 20, 2007 Share Posted November 20, 2007 the problem is with your logic, you need to use AND instead of OR, ie if the main url does not equal "www.mywebsite.co.uk" AND the main url does not equal "mywebsite.co.uk" then echo, which in PHP looks like ... if ($mainurl!=$main && $mainurl!=$main2) { Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.