?
Solved

How to remove this error: "PHP Notice:  Undefined index: ..."

Posted on 2008-10-26
4
Medium Priority
?
2,759 Views
Last Modified: 2012-05-05
- This line in PHP:
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) )  // <----- line 403
{
...
}

->Cause error in log file of apache:
[Sun Oct 26 13:49:48 2008] [error] [client 119.17.244.141] PHP Notice:  Undefined index:  security_code in /var/www/html/test.html on line 403

And many this errors, and LOG of apache is increase quickly

How can I resolve this problem?

Thanks in advance!
0
Comment
Question by:star6868
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 8

Accepted Solution

by:
fcardinaux earned 1000 total points
ID: 22806434
Try this:
<?php
if(!empty($_SESSION['security_code']) && !empty($_POST['security_code']) && ($_SESSION['security_code'] == $_POST['security_code']))  
{
// ...
}
?>

Open in new window

0
 
LVL 8

Expert Comment

by:fcardinaux
ID: 22806463
Here is the explanation: the empty() function does not generate any warning when the variable is not set (source: http://www.php.net/manual/en/function.empty.php). Furthermore, the condition inside the if construct is evaluated from left to right (http://www.php.net/manual/en/language.operators.php), and evaluation stops as soon as the result is known.

Thus, if $_SESSION['security_code'] or $_POST['security_code'] is not set, the third part of the condition is never evaluated ($_SESSION['security_code'] == $_POST['security_code']).
0
 
LVL 9

Expert Comment

by:Shahzad Fateh Ali
ID: 22807753
Hi Star,

Alternatively, you can get rid of these messages by turning off your error reporting.
use
error_reporting(0);
to do so.


For further reference visit
http://www.php.net/error_reporting
0
 
LVL 8

Expert Comment

by:fcardinaux
ID: 22807906
Shahzadfatehali,

If there is smoke in your house, do you look for fire or do you just open the windows?

Do not turn off error reporting. On the contrary, use error logs to make a more robust code.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question