Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$_SERVER['REQUEST_URI'];

Status
Not open for further replies.

rossmcl

Programmer
Apr 18, 2000
128
Any help much appreciated here.

I am trying to store visitor details of people that visit that use my website. I do it to a text file as my domain provide doesnt provide MySQL (actually they do, but it is blooming expensive for my hobbyist needs.)

What I am trying to do is add the URL of the site from which a visitor came to my page.

Originally I tried using $HTTP_SERVER_VARS['REMOTE_ADDR']

but it has never done anything. So then I stumbled across $_SERVER['REQUEST_URI'] - is THIS the variable I should use to get the URL from which a visitor has clicked onto get to my page.

I have seen it working here:
(but cannot use this code because I dont have mySQL, so I am wondering what the php command is that this person is using)

Any help very much appreciated
RM







<?php

$filename = "VisitorsDetailsBlog.txt";
$handle = fopen ($filename, "a+");
$todaydate = date("Y-m-d H:i:s");
$visitorInfo = $HTTP_SERVER_VARS['REMOTE_ADDR'];
$url = $_SERVER['REQUEST_URI'];

//if ($visitorInfo == "212.159.35.224")
//{
// do nothing
//}
//else
//{
fwrite($handle, "\r\n" . $todaydate . ' ' . $visitorInfo . ' ' . $url);
//}
fclose( $handle );

?>
 
you need $_SERVER[HTTP_REFERER] for where they came from,
$_SERVER['REQUEST_URI'] is the page that was requested.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
I have tried this before and it always comes up blank.

Any ideas? Here is my code.

====

<?php

$filename = "VisitorsDetailsBlog.txt";
$handle = fopen ($filename, "a+");
$todaydate = date("Y-m-d H:i:s");
$visitorInfo = $HTTP_SERVER_VARS['REMOTE_ADDR'];
$url = $_SERVER['REQUEST_URI'];
$test = $_SERVER[HTTP_REFERER]

//if ($visitorInfo == "212.159.35.224")
//{
// do nothing
//}
//else
//{
fwrite($handle, "\r\n" . $todaydate . ' ' . $visitorInfo . ' ' . $test . ' ' . $url);
//}
fclose( $handle );

?>

 
I have found with HTTP_REFERER that it is an empty string more often than not.

I stopped using it as it was unreliable.

D
 
why not replace
$visitorInfo = $HTTP_SERVER_VARS['REMOTE_ADDR'];

with
$visitorInfo = $_SERVER['REMOTE_ADDR'];
?

Copy/paste from php.net:

$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the webserver. There is no guarantee that every webserver will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the CGI 1.1 specification, so you should be able to expect those.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_SERVER; to access it within functions or methods, as you do with $HTTP_SERVER_VARS.

$HTTP_SERVER_VARS contains the same initial information, but is not an autoglobal. (Note that $HTTP_SERVER_VARS and $_SERVER are different variables and that PHP handles them as such)

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_SERVER and $HTTP_SERVER_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
 
rossmcl:

The site at the URL you posted is logging information that can be found in $_SERVER['HTTP_REFERER'].


Keep in mind, though, that for privacy purposes, most modern web browsers allow the user to turn off referer logging.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I just cannot believe that it seems to pick up a lot of URLs on his website, but it doesnt pick up ANY on mine.

Anyway, I made a couple of typos on my code which are now fixed.

The thing is, on his site, my website comes up when I go to his site from mine, but it doesnt come up when I go from his site to mine.

So my browser must be set up to do it, so why is it not doing it for my log file!!!

Any help very much appreciated.

Thanks
RM





=====

<?php

$filename = "VisitorsDetailsBlog.txt";
$handle = fopen ($filename, "a+");
$todaydate = date("Y-m-d H:i:s");
$visitorInfo = $HTTP_SERVER_VARS['REMOTE_ADDR'];
$url = $_SERVER['REQUEST_URI'];
$test = $_SERVER['HTTP_REFERER'];


fwrite($handle, "\r\n" . $todaydate . ' ' . $visitorInfo . ' ' . $test . ' ' . $url);

fclose( $handle );

?>
 
When you are going from his site to yours, is there a link provided, or are you typing in the URL for your site?

If it's the latter, there is no referer. Refering only exists when you click links.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I am clicking links both ways.

When I click on a link GOING TO his site, it shows up on his log file.

When I click on a link from his (or many other) sites COMING TO my site, diddly squat appears on my site.

Really frustrating, I put it down to 'HTTP_REFERER' being useless, but having now seen it (or something else that does exactly what I want!) in action for someone else, I REALLY REALLY REALLY want to know how they do it.

Any help very much appreciated as always

RM
 
Here it is:

<?php

$filename = "VisitorsDetailsBlog.txt";
$handle = fopen ($filename, "a+");
$todaydate = date("Y-m-d H:i:s");
$visitorInfo = $HTTP_SERVER_VARS['REMOTE_ADDR'];
$url = $_SERVER['REQUEST_URI'];
$test = $_SERVER['HTTP_REFERER'];

fwrite($handle, "\r\n" . $todaydate . ' ' . $visitorInfo . ' ' . $test . ' ' . $url);

fclose( $handle );

?>


Thanks very much in advance, much appreciated.
rossmcl
 
I don't get it.

If you are following a link to get from the remote website to your own website, $_SERVER['HTTP_REFERER'] should contain the foreign website URL.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Yes, the referer should contain the URL; I have experienced it is up to the browser to send that information. I have tried to get it to work but I couldn't either. I don't know why it doesn't work. Then I read the following on php.net and I've stopped using HTTP_REFERER since (note in Bold):

php.net said:
'HTTP_REFERER'
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.


D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top