Jump to content

PHP active page


jduffell

Recommended Posts

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
Share on other sites

$_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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.