Jump to content

fwrite/referrer problem


genericnumber1

Recommended Posts

[b]What the script is supposed to do[/b]
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.

[b]The Script[/b]
[code]
<?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);
?>
[/code]

[b]Display the missing page[/b]

[code]
<?php
echo "(" . $pageref . ")";
?>
[/code]

[b]The Problem[/b]
[list]
[*]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
[/list]

[b]A Single Log Example[/b]
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
Link to comment
Share on other sites

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))
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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..
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.