Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Include and php_self
- Pjotr Wedersteers
August 29, 2004, 4:31 pm
rate this thread
I have a page visit tracker script created after a video tutorial on writing
your own tracker.
// consider dbconnection already in place
$page = $_SERVER["PHP_SELF"];
$IP = $_SERVER["REMOTE_ADDR"];
$date_auto = time ();
$query = "INSERT INTO tracker (page, IP, date_auto ) VALUES ('$page', '$IP',
mysql_query ($query, $db_connection);
In the pages I want to track according to the tut all I have to do is add
<?php include ('http://wwwmyserver.com/tracker.php '); ?>
So I did. The weird bit is: in the tutorial the db lists the calling page's
name as PHP_SELF, but in my version it always shows the name of the
tracker.php script itself. I know I can use http_referer to get the info
about the page anyway, but can anyone explain WHY these results differ ? My
script is basically an identical copy of the tutorial script...
- Janwillem Borleffs
August 29, 2004, 6:15 pm
Re: Include and php_self
$_SERVER['PHP_SELF'] always contains the name of the file that includes
other files, or the file itself when it's retrieved from a remote source
(like in your case).
The tutorial probably uses PHP_SELF as an example value to indicate the page
BTW, another worakround would be to define the page variable before
$page = "tracker.php";
include ("http://wwwmyserver.com/tracker.php?page =$page");