-1

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 further 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
Community
  • 1
  • 1
User4283
  • 201
  • 2
  • 8

3 Answers3

1

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.

voretaq7
  • 212
  • 3
  • 11
0

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";
}
Kishor
  • 1,513
  • 2
  • 15
  • 25
-1

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).

Jakub
  • 20,418
  • 8
  • 65
  • 92
  • 1
    While I agree with disabling error reporting on production servers (or at least not sending it to the browser) the idea of "hide the messages and pretend the problem isn't there" is a bad one - It's the equivalent of saying "You can ignore those compiler messages - they're *just warnings*." -- If the code in question relies on the HTTP Referrer being set simply ignoring this notice could lead to problems later. Treat the cause (bad code), don't hide the symptom (NOTICE messages). – voretaq7 Oct 10 '11 at 16:02
  • @voretaq7, I fully agree. However if it is a production server, and purchased / 3rd party software, the best route would be to contact that party and muzzle the notices for said time. – Jakub Oct 10 '11 at 18:14
  • definitely, along with suitable noise being made at the vendor to fix their code. – voretaq7 Oct 10 '11 at 18:38