mcmuney Posted July 1, 2009 Share Posted July 1, 2009 I'd like to place some content on the footer page, which repeats on every page of a site, to show only on the homepage. For example, I'd want this content to show if the url path is either of the following: domain.com (including domain.com/) domain.com/index.php Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/164449-if-then-statement/ Share on other sites More sharing options...
Brian W Posted July 1, 2009 Share Posted July 1, 2009 <?php $page = pathinfo($_SERVER['PHP_SELF'],PATHINFO_FILENAME);//get the file name of the current page if($page == "index"){ //it neglects the extension, so hope you don't use index.html too echo "Footer HTML you want to show"; } ?> Link to comment https://forums.phpfreaks.com/topic/164449-if-then-statement/#findComment-867457 Share on other sites More sharing options...
mcmuney Posted July 2, 2009 Author Share Posted July 2, 2009 Didn't work. Every page shows the content. Strange. I displayed the $page info to see what was wrong and the $page equals index on every page, regardless of what the url shows. Link to comment https://forums.phpfreaks.com/topic/164449-if-then-statement/#findComment-867511 Share on other sites More sharing options...
johnathanhebert Posted July 2, 2009 Share Posted July 2, 2009 Maybe change it to test the 'REQUEST_URI' server variable... (which is the actual path from the URL) <?php $page = pathinfo($_SERVER['REQUEST_URI'],PATHINFO_FILENAME);//get the file name of the current page if($page == "index"){ //it neglects the extension, so hope you don't use index.html too echo "Footer HTML you want to show"; } ?> Link to comment https://forums.phpfreaks.com/topic/164449-if-then-statement/#findComment-867537 Share on other sites More sharing options...
Tonic-_- Posted July 2, 2009 Share Posted July 2, 2009 Something like this maybe? $index = "index.php"; $projects = "projects.php"; if($index==$_SERVER['REQUEST_URI']) { echo "INdex stuff here"; } elseif ($projects==$_SERVER['REQUEST_URI']) { echo "Projects here"; } Can't test this for you.. Personal server is offline atm. Link to comment https://forums.phpfreaks.com/topic/164449-if-then-statement/#findComment-867673 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.