Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with mod_substitute 18 35
What is this? I've never seen this... 2 28
How do I remove "" from json_encode 5 20
Dump data from mysql to xls php 10 17
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

735 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