Help with Undefined index.

I have a custom log file which uses fopen, fwrite, and fclose. Example :

[php]
// Log IP Address Of All Visitors
$filename = $_SERVER[‘DOCUMENT_ROOT’] ."/Logs/visitors_IP.txt";
$referred = $_SERVER[‘HTTP_REFERER’];
if ($referred == “”) {
$referred = “Direct Request”;
}
$handle = fopen($filename, “a”);
$content = “[ " . date( ‘M d, Y, g:i a’ ) . " ]” . " Visitor_IP = ( " . $_SERVER[‘REMOTE_ADDR’] . " )" . “\n” . “Linked from = ( " . $referred . " )”;
fwrite($handle, $content . “\n”);
fclose($handle);
[/php]

I’m getting a notice when it’s a direct request :

Notice: Undefined index: HTTP_REFERER

This puts IE in quirks mode as the notice gets printed above the html !doctype. Thanks in advance for any help on this.

I’m thinking there is no way around this so I disabled error reporting for IE only as error reporting will be disabled for all browsers when site is up and live anyways. I’m still willing to hear any suggestions on this subject though.

HTTP_REFERER means the url the browser comes from before your website so if you just open IE and navigate right away to ur page it will undrfined because previous page does not exist

to fix that problem just do it like this

[php]
$referred = @$_SERVER[‘HTTP_REFERER’];
[/php]

:)Thanks for that Wilson382, good stuff.

Sponsor our Newsletter | Privacy Policy | Terms of Service