Forum Moderators: coopster

Message Too Old, No Replies

Undefined index: HTTP REFERER

         

Doood

3:21 pm on Apr 23, 2008 (gmt 0)

10+ Year Member



PHP Notice: Undefined index: HTTP_REFERER

I have a script that shows the referring sites but the error_log is full of these PHP Notices. I know it's not a big deal and notices can be turned off but I'd like to fix it since there are 20K+ of these per day and need to watch for other notices.

The error says it's the second line.


putenv ( "REMOTE_ADDR=".$HTTP_SERVER_VARS["REMOTE_ADDR"] ) ;
if( $HTTP_SERVER_VARS["HTTP_REFERER"] ) {
putenv ( "HTTP_REFERER=".$HTTP_SERVER_VARS["HTTP_REFERER"] ) ;
} else { putenv("HTTP_REFERER=noref"); }
PassThru("./path/to/script");

I'm using PHP 5.1.6 and register_long_arrays is turned on.

Should it use isset like


if(isset ( $HTTP_SERVER_VARS["HTTP_REFERER"] ))

and should I change all of those $HTTP_SERVER_VARS to $_SERVER

jatar_k

4:44 pm on Apr 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



yes, I would change all of those to $_SERVER

I would use empty [php.net], then you could test whether not set or empty it would put 'noref'

Doood

6:05 pm on Apr 23, 2008 (gmt 0)

10+ Year Member



With the original code posted above, it does set a cookie which you can view on the page source in a javascript tag that either has the referring domain or noref listed.

If I use 'empty' in the 'if' statement then would that not do away with the 'else' noref part? Maybe I'm just confused.

jatar_k

7:45 pm on Apr 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



alright

if(!empty($_SERVER['HTTP_REFERER'])) putenv('HTTP_REFERER=' . $_SERVER['HTTP_REFERER']);
else putenv('HTTP_REFERER=noref');