jduffell Posted September 30, 2009 Share Posted September 30, 2009 Hi, i've been using a little php in my navigation for some time, and it basically allows me to enfore the active class when the releavent page is selected. However i've recently changed my pages from portfolio.php to /portfolio/ so i've simply placed it in a seperate folder to make the url look nicer, however this cause the script to break. This is the method i'm using http://www.sebastiansulinski.co.uk/tutorials/show_item/56/active_button_with_php_and_css any help welcome thanks Link to comment https://forums.phpfreaks.com/topic/176110-php-active-page/ Share on other sites More sharing options...
cunoodle2 Posted September 30, 2009 Share Posted September 30, 2009 I would say that the error in your code is on line 37 Link to comment https://forums.phpfreaks.com/topic/176110-php-active-page/#findComment-927994 Share on other sites More sharing options...
jon23d Posted September 30, 2009 Share Posted September 30, 2009 $_SERVER['SCRIPT_NAME'] includes path information, try: echo "<pre>"; print_r($_SERVER); echo "</pre>"; to see what I mean. If you compare script name, with path, then the match will never occur. I use something like this to get what you are looking for often: // get the requested URL $requested_url = $_SERVER['REQUEST_URI']; // remove anything before the current folder from the requested url $sub_folders = str_replace($_SERVER['DOCUMENT_ROOT'], "", getcwd()); // now remove the sub folders from the requested url $requested_url = str_replace($sub_folders, "", $requested_url); You may need to trim slashes or perform other post-processing. Link to comment https://forums.phpfreaks.com/topic/176110-php-active-page/#findComment-928013 Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 You may also find this usefull.. <?php echo __FILE__ ?> Link to comment https://forums.phpfreaks.com/topic/176110-php-active-page/#findComment-928016 Share on other sites More sharing options...
jon23d Posted September 30, 2009 Share Posted September 30, 2009 Beware though, __FILES__ will show the filename of the current script, including required or included ones! Link to comment https://forums.phpfreaks.com/topic/176110-php-active-page/#findComment-928023 Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 Beware though, __FILES__ will show the filename of the current script, including required or included ones! Certainly worth bearing in mind, but in my opinion the fact that makes it so darn usefull. The amount of trouble I had keeping my file structure accurate with nestled folders and includes before I spotted somewhere the use of __FILE__ ... anyway I digress. Link to comment https://forums.phpfreaks.com/topic/176110-php-active-page/#findComment-928041 Share on other sites More sharing options...
jon23d Posted October 1, 2009 Share Posted October 1, 2009 Interesting, I never considered its usefulness in that light, but yeah, I bet it would be. I've been storing the domain's subfolder (or lack of), along with protocol and domain in $_REQUEST['http_root'] for years to make things easier Link to comment https://forums.phpfreaks.com/topic/176110-php-active-page/#findComment-928057 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.