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!

HTTP_REFERER is always blank

Status
Not open for further replies.

MartinCouture

Technical User
Feb 16, 2002
57
CA
I'm playing around with REFERER and have problems with my index.php page...
Code:
$refererFile = "scripts/counter/referer.txt";
$referer = getenv("HTTP_REFERER");
$host = getenv("HTTP_HOST") ;
$url=  getenv("REQUEST_URI");

$logEntry=strftime("%d/%m/%y %H:%M",time())." : Referer = $referer  |  Host = $host  |  URL = $url\n";

$file = @fopen($refererFile, "a");
fwrite($file, $logEntry);
fclose($file);

but when you read the text file, referer.txt, I have 25/02/02 23:10 : Referer = | Host = localhost:8080 | URL = /index.php

instead of the previous web page visited. I always make sure I visit at least 2 or 3 different web sites before accessing index.php.

Here's the structure of index.php (structure is the probable cause :))

Code:
<HTML>
<HEAD>
<TITLE>Index Page</TITLE>
</HEAD>
<?
$refererFile = &quot;scripts/counter/referer.txt&quot;;
$referer = getenv(&quot;HTTP_REFERER&quot;);
$host = getenv(&quot;HTTP_HOST&quot;) ;
$url=  getenv(&quot;REQUEST_URI&quot;);
$logEntry=strftime(&quot;%d/%m/%y %H:%M&quot;,time()).&quot; : Referer = $referer  |  Host = $host  |  URL = $url\n&quot;;

$file = @fopen($refererFile, &quot;a&quot;);
fwrite($file, $logEntry);
fclose($file);
?>
<FRAMESET cols=&quot;185,*&quot; FRAMEBORDER=&quot;0&quot; BORDER=0>
  <FRAME SRC=&quot;menuindex.html&quot; NAME=&quot;nav&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; target=&quot;body&quot;>
  <FRAME SRC=&quot;mainindex.php&quot; NAME=&quot;body&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; target=&quot;body&quot;>
</FRAMESET>

<NOFRAMES>
<BODY>
You need a frame capable browser ! Update your browser...
</BODY>
</NOFRAMES>
</HTML>

This should fill the text file with all the referer sites, right ?
I also tried straight $HTTP_REFERER with the same results...

Help !
 
So you have a page that links to your index.php and when you click that link $HTTP_REFERER is blank? That seems very odd to me... //Daniel
 
Exactly :-
That's what seems odd... What I'm running:
. Apache : apache_1.3.23-win32-x86
. IE 6.02 with a privicy setting of Medium (blocks third party cookies)
. Behing NeoWatch v2.4 firewall (shouldn't block referer)

So I still think it's the code in index.php

I'll put up the link later today on a public server with the contents of the text file in mainindex.php (the body)
 
check the value of the var $_SERVER['HTTP_REFERER'].

if you use PHP 4.1.x it doesn't extract the values of the SERVER vars, unless you set it to.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Well I found the mistake...

It's me, not the code :)

My way of testing the referer was to browse the internet and then type the link in the adress bar thinking that the referer in that case would be the last web site visited.

I should have paid attention to danielhozac...

The
Code:
$_SERVER['HTTP_REFERER']
does also work, thanks Anikin.

Here's the link, so if you click on it, you should get as referer tek-tips.com


Here's the code for the curious :
Code:
<b>Referer using echo $HTTP_REFERER : </b><?echo $HTTP_REFERER;?><br><br>
<b>Referer using echo $HTTP_SERVER_VARS[&quot;HTTP_REFERER&quot;] : </b><?echo $HTTP_SERVER_VARS[&quot;HTTP_REFERER&quot;];?><br><br>
<b>Referer using echo getenv(&quot;HTTP_REFERER&quot;) : </b><?echo getenv(&quot;HTTP_REFERER&quot;);?><br><br>
<b>Referer using echo &quot;{$HTTP_HOST}{$REQUEST_URI}&quot; : </b><?echo &quot;{$HTTP_HOST}{$REQUEST_URI}&quot;;?><br><br>
<b>Referer IP using echo $REMOTE_ADDR : </b><?echo $REMOTE_ADDR;?><br><br>
<b>Referer's Browser using echo $HTTP_USER_AGENT : </b><?echo $HTTP_USER_AGENT;?><br><br>
 
Martin - Ive put that code in your 2nd to last post into a php page and all I get is $REMOTE_ADDR value as an IP address. All others are still blank!

Any other ideas anyone? I need to get the domain of the page! Miles

Those Micros~1 guys sure know what they doing!
 
I cut and paste the code I had there and pasted it between the <body> </body> of a generic html file, which I renamed index.php and posted it here:

I also tried my old test:

The results were:
Referer using echo $http_REFERER :

Referer using echo $http_SERVER_VARS[&quot;http_REFERER&quot;] :

Referer using echo getenv(&quot;http_REFERER&quot;) :
Referer using echo &quot;{$http_HOST}{$REQUEST_URI}&quot; : /test/index.php

Referer IP using echo $REMOTE_ADDR : 24.226.120.xxx

Referer's Browser using echo $http_USER_AGENT :

When I first tried this code, everything was working perfectly, while now, some of the code doesn't work. The only change between now and then is that the code resides on my machine which is behind a different firewall. I will post the code back up on the cgi spaceports account to see if my firewall has an effect on the results. -----------------
[flush]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top