View Full Version : Finding Page Name, not Script Name

02-10-2003, 09:42 PM
It seems that this forum will be my new home for a few days... but that's okay, ya'll seem like a nice enough group of people. :)

I want to write a short php script to act as a rudimentary stats gatherer. I'm thinking along the lines of writing one script, then including it in all the other pages. In other words, say I have index.shtml, about.shtml, and contact.php. I would like one script, stats.php, that I can use on the different pages (either by <!--#include file="php/stats.php"--> or include ("php/stats.php"); depending on how the page is parsed).

It'll just dump all the data in the same file, something along the lines of:

1. index.shtml refr: yahoo.com Mozilla /4.0
2. contact.php refr: index.shtml Mozilla /4.0
3. index.shtml 987.65.43.210 refr: google.com Opera 6.0
4. index.shtml refr: contact.php Mozilla /4.0
5. about.shtml 987.65.43.210 refr: index.shtml Opera 6.0

But to do that I'll need the page name into which the the script was included. I can't just use $PHP_SELF because it'll just return the name of the script, not the page (I even checked to see if there was a $HTTP_SELF... no luck).

What variable am I looking for to find the name of the page in which stats.php has been inserted?!


02-11-2003, 12:57 AM
if you <?include 'stats.php';?> then $_SERVER['PHP_SELF'] should contain the name of the calling page not of stats.php

so if foo.php was

<?include 'bar.php';?>


bar.php contained

<?echo $_SERVER['PHP_SELF'];?>

then the output of foo.php should be '/foo.php'
which is I think what you want ?

02-11-2003, 04:57 PM
Thank you, but it doesnt work for me.

I have page.shtml which contains:
<h1>This page is: <!--#include file="script.php"--></h1>

and script.php contains:
echo $_SERVER['PHP_SELF'];

page.shtml displays:
This page is: /script.php

Any more suggestions? I know this has to be possible, it's just a matter of how.

02-12-2003, 07:12 PM
Got it! It took a heck of a lot of researching and pestering programming gurus, but the variable I'm looking for is: $REQUEST_URI

Just incase anyone else needs to know :)