killerchutney Posted November 11, 2007 Share Posted November 11, 2007 Hello, first off I am very new with PHP, but have alot of experience in similar languages such as pawn (very similar syntax from what ive seen of PHP). Ok, as you may have guessed from the subject I need to get the URL of the current page from an include. http://www.killerchutney.com/lol.php (aptly named ) is the page I need to detect the URL of. header.php is included in that page. For asthetical reasons header.php contains the PHP script. From using the PHP documentation, and a tutorial site I have this in a part of header.php: <div <?php function getpage() { $this_page = $_SERVER['PHP_SELF']; return $this_page;} if (getpage() == 'index.php'){ echo ('id="content"');} elseif (getpage() == 'lol.php'){ echo ('style="background-color:#ff00f6;"');} elseif (getpage() == '/templates/header.php'){ echo ('style="background-color:#3cff00;"');} else{ echo ('style="background-color:#000000;"'); }?>> it works fine, but as this is located in header.php, it always detects header.php - I need it to detect the main URL - the URL of lol.php (the page header.php is included in) is there any way to do this? Thanks. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 11, 2007 Share Posted November 11, 2007 When you include a file, what effectively happens is that all of the code inside the included file is dumped inside the file doing the including. Therefore, you need to place this line: $this_page = $_SERVER['PHP_SELF']; Before the include is done, and take it out of header.php Ok, as you may have guessed from the subject I need to get the URL of the current page from an include. We're supposed to guess that question from the subject 'pretty simple question'? You might be clairvoyant - im not though. Quote Link to comment Share on other sites More sharing options...
killerchutney Posted November 12, 2007 Author Share Posted November 12, 2007 thank you, that did the trick but the subject name was called something relevant before I edited it - I saw questions with names like 'plz help' that were posted about 30 minutes AFTER my post, and still solved when I had only like 3 views. So, for some reason I thought to change the name to follow those requests. Quote Link to comment 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.