开发者

php notice Undefined index [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

PHP: “Notice: Undefined variable” and “Notice: Undefined index”

I'm getting the following php NOTICES on my web. I've check the line mention in notice but those lines are commented. What fur开发者_JAVA技巧ther i can check to fix this notice?

PHP 5.0.4 (WINNT)
NOTICE: [8] Undefined index: HTTP_REFERER Line: 4 File: d:\IpPlan\www\adodb\adodb.inc.php(1) : eval()'d code
NOTICE: [8] Undefined index: HTTP_REFERER Line: 4 File: d:\IpPlan\www\adodb\adodb-time.inc.php(1) : eval()'d code
NOTICE: [8] Undefined index: HTTP_REFERER Line: 4 File: d:\IpPlan\www\adodb\adodb-iterator.inc.php(1) : eval()'d code
NOTICE: [8] Undefined index: HTTP_REFERER Line: 4 File: d:\IpPlan\www\class.dbflib.php(1) : eval()'d code
NOTICE: [8] Undefined index: HTTP_REFERER Line: 4 File: d:\IpPlan\www\config.php(1) : eval()'d code


You are, at some point, attempting to access the index HTTP_REFERRER in an array, but no value was ever set for that index. Typically this is because you've got something like $_SERVER['HTTP_REFERRER'] in your code.

The fix is to not access an array element that may be undefined without first checking to see if it's defined (using isset()). See the PHP manual for more information.


Use isset() function to check if the variable is set.

Use this instead of what you are using now.

if (isset($_SERVER['HTTP_REFERER'])){
echo $_SERVER['HTTP_REFERER'];
//and whatever you need to go.
}

else{
echo "Referer was null";
}


You could just disable noticed from being displayed (they are just notices after all, notifying you of something, not an error, or warning).

Details here: http://php.net/manual/en/function.error-reporting.php

You can set this in your script:

error_reporting(E_ALL ^ E_NOTICE);

Or look up error reporting in your PHP.INI file and edit it there (recommended).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜