Solved

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

Posted on 2008-10-26
4
2,753 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 250 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 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