jarvis Posted January 15, 2010 Share Posted January 15, 2010 Hi, Am probably being thick (not enough coffee yet!!!). Why is the below not working: $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; $filename = basename($pageURL); echo $filename; //debug if ($filename == 'index.php') { echo 'home'; } elseif ($filename == 'about.php') { echo 'about'; } elseif ($filename == 'services.php') { echo 'services'; } elseif ($filename == 'affiliate.php') { echo 'affiliate'; } elseif ($filename == 'links.php') { echo 'links'; } else($filename == 'contact.php') { echo 'contact'; } The idea is it get the filename from the URL and depending which page, a different image will be shown. Sorry it's a silly question. Your help is appreciated! Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/188555-elseif-issue/ Share on other sites More sharing options...
trq Posted January 15, 2010 Share Posted January 15, 2010 Firstly, else's cannot have an expression, so this line.... } else($filename == 'contact.php') { is syntactically incorrect. Have you got a mod_rewrite rule in place to force this file to handle these requests? Quote Link to comment https://forums.phpfreaks.com/topic/188555-elseif-issue/#findComment-995454 Share on other sites More sharing options...
jarvis Posted January 15, 2010 Author Share Posted January 15, 2010 Hi thorpe, No, no rewrite in place. I thought I could just grab the filename, then do a simple statement to match the filename, if it matches, show a particular image!? Quote Link to comment https://forums.phpfreaks.com/topic/188555-elseif-issue/#findComment-995461 Share on other sites More sharing options...
trq Posted January 15, 2010 Share Posted January 15, 2010 That makes no sense. If the url is http://yourdomain.com/links.php your server is going to look for a file called links.php (not the script you have posted) etc etc. Quote Link to comment https://forums.phpfreaks.com/topic/188555-elseif-issue/#findComment-995463 Share on other sites More sharing options...
jarvis Posted January 15, 2010 Author Share Posted January 15, 2010 Sorry to sound daft, but if $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; $filename = basename($pageURL); echo $filename; //debug Can give me the filename, then don't I just need to say if filename = $filename, then show x y or z? As $filename would be links.php, so don't I just need to say, it $filename is equal to links.php show whatever? Quote Link to comment https://forums.phpfreaks.com/topic/188555-elseif-issue/#findComment-995465 Share on other sites More sharing options...
jarvis Posted January 15, 2010 Author Share Posted January 15, 2010 Solved: $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; $filename = basename($pageURL); #echo $filename; //debug if ($filename == 'index.php') { echo 'home'; } elseif ($filename == 'about.php') { echo 'about'; } elseif ($filename == 'services.php') { echo 'services'; } elseif ($filename == 'affiliate.php') { echo 'affiliate'; } elseif ($filename == 'links.php') { echo 'links'; } else { echo 'contact'; } Quote Link to comment https://forums.phpfreaks.com/topic/188555-elseif-issue/#findComment-995469 Share on other sites More sharing options...
trq Posted January 15, 2010 Share Posted January 15, 2010 Obviously this file is being included within another. You failed to mention that. Always best to provide the relevant information. Quote Link to comment https://forums.phpfreaks.com/topic/188555-elseif-issue/#findComment-995516 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.