Spring Posted February 23, 2011 Share Posted February 23, 2011 Is there a function to check the name of the current page? Such as login.php or something like that? If not, does anyone have a custom function already created? Quote Link to comment https://forums.phpfreaks.com/topic/228547-is-there-a-function-to-check-the-name-of-the-current-page/ Share on other sites More sharing options...
jcbones Posted February 23, 2011 Share Posted February 23, 2011 $_SERVER['PHP_SELF']; Quote Link to comment https://forums.phpfreaks.com/topic/228547-is-there-a-function-to-check-the-name-of-the-current-page/#findComment-1178425 Share on other sites More sharing options...
Spring Posted February 23, 2011 Author Share Posted February 23, 2011 Didn't really work how I wanted it to, I want to change the HTML class to 'current' depending on what page they're on. For example: $page = $_SERVER['PHP_SELF']; if($page === '/blah/game/index.php') { echo 'class="current"'; } if($page === '/blah/game/register.php') { echo 'class="current"'; } That didn't work, any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/228547-is-there-a-function-to-check-the-name-of-the-current-page/#findComment-1178440 Share on other sites More sharing options...
jcbones Posted February 23, 2011 Share Posted February 23, 2011 You are looking for the full path, and not just the current page. Try: if(__FILE__ === '/blah/game/index.php') __FILE__ The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances. Quote Link to comment https://forums.phpfreaks.com/topic/228547-is-there-a-function-to-check-the-name-of-the-current-page/#findComment-1178443 Share on other sites More sharing options...
Spring Posted February 23, 2011 Author Share Posted February 23, 2011 Thanks a lot, I really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/228547-is-there-a-function-to-check-the-name-of-the-current-page/#findComment-1178472 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.