Jack8900 Posted August 2, 2009 Share Posted August 2, 2009 Hi there, I was wondering if anyone could help me, I have been searching high and low and no-one can seem to come up with a solution. This is the code I have: <? $url = explode("/", $_SERVER["SCRIPT_NAME"]); if($url == "results.php?submit=Search&cat[0]=19") { echo("<img src=headercamper.jpg width="785" height="250">"); } else) { echo("<img src=header.jpg width="785" height="250">"); } ?> Could someone please point me in the right direction of where i'm going wrong. Thanks in advance, Jack Quote Link to comment https://forums.phpfreaks.com/topic/168539-solved-displaying-an-image-based-on-url/ Share on other sites More sharing options...
timmah1 Posted August 2, 2009 Share Posted August 2, 2009 Try this <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } $url = curPageURL(); if($url == "results.php?submit=Search&cat[0]=19") { echo("<img src=headercamper.jpg width="785" height="250">"); } else) { echo("<img src=header.jpg width="785" height="250">"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/168539-solved-displaying-an-image-based-on-url/#findComment-889066 Share on other sites More sharing options...
Jack8900 Posted August 2, 2009 Author Share Posted August 2, 2009 Hi Tim, Thanks for your quick response, I updated my webpage with that but now none of the website displays it's just pure blank. Maybe an error? Jack Quote Link to comment https://forums.phpfreaks.com/topic/168539-solved-displaying-an-image-based-on-url/#findComment-889069 Share on other sites More sharing options...
Jack8900 Posted August 2, 2009 Author Share Posted August 2, 2009 Tried again it says Parse error: syntax error, unexpected T_LNUMBER in *URL REMOVED* on line 24 Quote Link to comment https://forums.phpfreaks.com/topic/168539-solved-displaying-an-image-based-on-url/#findComment-889071 Share on other sites More sharing options...
timmah1 Posted August 2, 2009 Share Posted August 2, 2009 There was an extra ) right after the else Here ya go, try this <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } $url = curPageURL(); if($url == "results.php?submit=Search&cat[0]=19") { echo("<img src=headercamper.jpg width="785" height="250">"); } else { echo("<img src=header.jpg width="785" height="250">"); } ?> You can see here http://cheezyfries.net/testing/index.php?id=4 Quote Link to comment https://forums.phpfreaks.com/topic/168539-solved-displaying-an-image-based-on-url/#findComment-889074 Share on other sites More sharing options...
Jack8900 Posted August 2, 2009 Author Share Posted August 2, 2009 Hi Tim, Thanks very much for all your help I managed to get it working using this code <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } $url = curPageURL(); if($url == "http://domain.co.uk/results.php?submit=Search&cat[0]=19") { echo("<img src=images/headercamper.jpg>"); } else { echo("<img src=images/header.jpg>"); } ?> But it wont work if I use if($url == "results.php?submit=Search&cat[0]=19") without the prefix domain and that means if I visit the website using http://www.domain.co.uk or http://domain.co.uk then one of them won't work but one will. Hopefully this makes sense. Jack Quote Link to comment https://forums.phpfreaks.com/topic/168539-solved-displaying-an-image-based-on-url/#findComment-889076 Share on other sites More sharing options...
timmah1 Posted August 2, 2009 Share Posted August 2, 2009 So are you saying you got it to work or not? Quote Link to comment https://forums.phpfreaks.com/topic/168539-solved-displaying-an-image-based-on-url/#findComment-889079 Share on other sites More sharing options...
Jack8900 Posted August 2, 2009 Author Share Posted August 2, 2009 If i visit the website using the code above it will work if I visit http://domain.co.uk/results.php?submit=Search&cat=19") But if i visit the website at http://www.domain.co.uk/results.php?submit=Search&cat=19") (WITH A WWW PREFIX) it will not work Thanks, Jack Quote Link to comment https://forums.phpfreaks.com/topic/168539-solved-displaying-an-image-based-on-url/#findComment-889080 Share on other sites More sharing options...
Jack8900 Posted August 2, 2009 Author Share Posted August 2, 2009 All fixed now! Thanks very much for your help Tim!!! <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } $url = curPageURL(); if($url == "http://www.domain.co.uk/results.php?submit=Search&cat[0]=19") { echo("<img src=images/headercamper.jpg>"); } else if($url == "http://domain.co.uk/results.php?submit=Search&cat[0]=19") { echo("<img src=images/headercamper.jpg>"); } else { echo("<img src=images/header.jpg>"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/168539-solved-displaying-an-image-based-on-url/#findComment-889086 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.