Jump to content


Photo

fwrite/referrer problem


  • Please log in to reply
3 replies to this topic

#1 genericnumber1

genericnumber1
  • Members
  • PipPipPip
  • Advanced Member
  • 1,858 posts

Posted 13 September 2006 - 01:59 AM

What the script is supposed to do
It's a custom error page (404) and it basically just logs the missing page, and some other information.
I'm seeing this as perhaps being a server problem? It's been driving me crazy.

The Script
<?php
$pageref = $_SERVER['HTTP_REFERER']; // (Not REFERRER)
$date = date("m/d/y");

$error = "<b>404 ERROR - $pageref - $date</b><br>";
$error .= "Username: " . htmlentities($_COOKIE['u']) . "<br>";
$error .= "IP Address: " . $_SERVER['REMOTE_ADDR'] . "<br>";
$error .= "User Agent: " . htmlentities($_SERVER['HTTP_USER_AGENT']) . "<br><br>";

$handle = fopen("logs/zomgerrors.htm", "r+");
fwrite($handle, $error);
?>

Display the missing page

<?php
echo "(" . $pageref . ")";
?>

The Problem
  • When I echo $pageref, it is always blank or "()"
  • When it writes to the log it always writes twice, one of them without the $pageref

A Single Log Example
404 ERROR - - 09/12/06
Username: Generic
IP Address: -edited-
User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6

404 ERROR - http://www.url.com/missingpage.php - 09/12/06
Username: Generic
IP Address: -edited-
User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6

#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 13 September 2006 - 02:45 AM

That is very odd.  Your code looks fine.  I'm pretty sure it's to do with the server, and your script is being called twice for each request.  You might want your script do dump the contents of $_SERVER and see if there's clues in there (use $server_vars = print_r($_SERVER, true))

#3 genericnumber1

genericnumber1
  • Members
  • PipPipPip
  • Advanced Member
  • 1,858 posts

Posted 13 September 2006 - 03:09 AM

Well, when I dumped $_SERVER I didn't notice anything odd, the referer was there etc...

Proposed diagnosis:
Server is tweaking out.

EDIT:
I originally was testing the REFERER with a link on the 404.php page, I tried actually being redirected to the 404.php from "flakneflkanfe.php" (obviously it wasnt there) but the log still posted

404 ERROR - - 09/12/06
Username: Generic
IP Address: -edited-
User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6

404 ERROR - http://www.url.com/404.php - 09/12/06
Username: Generic
IP Address: -edited-
User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6

So do you think it's a good diagnosis that for some reason it doesn't get the referrer when it is redirected to 404.php by the .htaccess file and when it gets to 404.php it posts a value with a blank referrer, then for some reason the page reloads and posts that it was referred to by 404.php?

#4 genericnumber1

genericnumber1
  • Members
  • PipPipPip
  • Advanced Member
  • 1,858 posts

Posted 13 September 2006 - 03:36 AM

I stripped out every little thing except for the bare minimum (in an attempt to pull out anything that would refresh the page) and now it is only posting one log, but it doesn't have the referrer in it...

I'm not just being an idiot and assuming that if I visit "alkknfelakn.php" my browser will send that as the referrer to 404.php when that's not how it works am I?

EDIT:
Sorry, I'm tired and I just thought "Wait.... it's a header redirect so it's not gonna have the requested page, CRAP!" So yeah, now that I've sounded quite stupid I'd like to say thanks for helping me, I'll just use the referrer to see what page had the broken link in it..




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users