Jump to content

[SOLVED] pretty simple question


killerchutney

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

thank you, that did the trick :D

 

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.

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.