PDA

View Full Version : PHP includes; detecting the calling page?


Juparis
08-12-2005, 01:09 PM
Once again, I've run into a little problem with my undeveloped PHP skills..

Plain and simply, I'd like to know: Is it possible for a PHP include to detect which page it's being loaded onto?

Example: If I were to have an include such as footer.php, and it is being called onto a page called works3t.php... Since this isn't works2t.php, would it be possible to change a small segment of the footer.php?

My actual situation is changing a different segment of a JavaScript code, but that's nothing to worry about until I can figure out how to detect the pages (if possible)..

Is this making sense to anyone? :confused:
Thanks in advance!

RysChwith
08-12-2005, 03:24 PM
I don't know of any particularly clever way to do it, but you could have the calling page set a variable, like $pagename or some such, and then have the footer use that to determine the page.

Rys

AaronCampbell
08-12-2005, 05:33 PM
inside footer.php:if (strpos($_SERVER['PHP_SELF'],'works3t') !== false){
//do something
} else {
//do something else
}$_SERVER['PHP_SELF'] will return the currently running script, so if you are at http://yoursite.com/dir/page1.php, it will return /dir/page1.php. Even if page1.php has included footer.php, and footer.php is doing the check.

Juparis
08-13-2005, 07:45 AM
Hmm...

Is this possible to use the same method in a JavaScript file? I'll test it now, but no guarantees that my coding can do anything at all, heh...

Juparis
08-13-2005, 12:34 PM
Edit: Though I saw my last problem, I have a new one that I don't understand...

Warning: Wrong parameter count for strpos() in public_html/*****.php on line 41

This is a first time I'm using the strpos() command in PHP, so forgive my ignorance to my mistake.. Here's line 41:

switch (strpos($_SERVER['PHP_SELF']))

(and then several cases after that)