473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Include and php_self

Hello again,

I have a page visit tracker script created after a video tutorial on writing
your own tracker.
<?PHP
// 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',
'$date_auto')";
mysql_query ($query, $db_connection);
mysql_close ($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...

TIA,
Pjotr

Jul 17 '05 #1
2 3608
Pjotr Wedersteers wrote:
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...


$_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
name.

BTW, another worakround would be to define the page variable before
inclusion:

<?php
$page = "tracker.php";
include ("http://wwwmyserver.com/tracker.php?page=$page");
?>
JW

Jul 17 '05 #2
Janwillem Borleffs wrote:
Pjotr Wedersteers wrote:
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...


$_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 name.

Thanks, that cleared up that mystery. Remote file. I was stomped. No more!
Pjotr
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gbona | last post by:
While running the following piece of code if (eregi("config.php",$PHP_SELF)) { Header("Location: index.php"); die(); } I get the following error Notice: Undefined variable: PHP_SELF in...
43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
5
by: Maja | last post by:
here's situation: i have installed php 5 and apache 2.0. i can call my page with: localhost\\subdir\page.php inside my page i use links like this:
3
by: Dave | last post by:
guys say if I include("anyfile.php") into a file. Is it possible for me to access the calling page from anyfile.php. Can I do something like this for instance:: if callingpage ==...
12
by: Don | last post by:
What's the PHP equivalent for the following? if(window.location == "http:/site.com/page1.html") { } else { }
8
by: Greg A | last post by:
Hi: I have my index.php page. For the header, sidebar, and footer, those are separate php pages that I call into the index.php page. My sidebar.php page has a form in it, that works fine if...
4
by: Jim Carlock | last post by:
Are the XSS / Cross Site Scripting attacks fixed in Version 4.44? I'm seeing that $_SERVER doesn't return the $_SERVER appended to it. I was just messing with a few things and noticed that...
18
by: zoilus | last post by:
Can not determine how "<?=PHP_SELF?>" is supposed to work. The below is the line of code. <!-- <form name="search" method="post" action="<?=$PHP_SELF?>"--> When the above statement is run the...
10
by: SoulIntruder | last post by:
Hello folks. I have a beginners question. I have such script: <?php $User = $_POST; $Password = $_POST; $Database = $_POST;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.