monkeybidz Posted July 10, 2011 Share Posted July 10, 2011 Need a little help. What I am try to do, is : If current page == index.php echo "this" else echo "that" Link to comment https://forums.phpfreaks.com/topic/241549-help-if-statement/ Share on other sites More sharing options...
QuickOldCar Posted July 10, 2011 Share Posted July 10, 2011 <?php $current_page = basename($_SERVER['REQUEST_URI']); if (strpos($current_page, "?") !== false){ $current_page = reset(explode("?", $current_page)); } if($current_page == "index.php") { echo "this"; } else { echo "that"; } ?> Link to comment https://forums.phpfreaks.com/topic/241549-help-if-statement/#findComment-1240724 Share on other sites More sharing options...
QuickOldCar Posted July 10, 2011 Share Posted July 10, 2011 Use this instead. <?php $server_page = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); echo $server_page."<br />"; $current_page = end(explode("/", $server_page)); if($current_page == "index.php") { echo "this"; } else { echo "that"; } ?> Link to comment https://forums.phpfreaks.com/topic/241549-help-if-statement/#findComment-1240727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.