I am hoping someone on this forum can help me with a recent issue. I am working on creating a login page for users of my site. The form where they give login details looks like this (CSS not included here, so if you test it, remove the class="" tags in the input):
<form action=login.php method="post">
<span>Email Address:</span><br><input type="text" name="user">
<span>Password:</span><br><input type="password" name="pass">
<input class="leftButton" type="submit" name = "login" value="Log In" action="login.php">
<input class="rightButton" type="submit" name = "new" value="New Account" action="newAccount.php">
</form>
This correctly directs users to either the login page or the new account page. If they fill out some form data and press log in, it takes them to this test page:
I also have a custom error handling function:
function errorHandler($e_number, $e_message, $e_file, $e_line, $e_vars){
//import the global variables above.
//TODO: Find a way to not use globals for this function.
global $Debug_Mode, $errorLogEmail;
//build the error message
$errorMessage="An error has occured in script $e_file on line $e_line: $e_message\n<br />";
$errorMessage.= "Date/Time: " . date('n-j-Y H:i:s') . "\n<br />";
$errorMessage.="<pre>" . print_r($e_vars, 1) . "</pre>\n<br />";
if(Debug_Mode){
echo '<div id = "error">' . $errorMessage . '</div><br />';
}else{
error_log($errorMessage, 1, $errorLogEmail);
echo '<div id = "error"> A system error has occured, and the administrator has been notified. We aplogize for the inconvenience. Please try again later. </div><br />';
}
die("Exiting Application with errors");
}
//tells PHP to use this as the default error handler.
set_error_handler('errorHandler');
Login.php:
if (isset($_POST['user']))
echo "User set <br />";
if(!empty($_POST['user']))
echo "User not empty<br />";
if(isset($_POST['pass']))
echo "Pass is set<br />";
if(!empty($_POST['pass']))
echo "Pass not empty<br />";
trigger_error("Data Dump"); //dump all variables on screen;
if (isset($_POST['user']) && !empty($_POST['user']) && isset($_POST['pass']) && !empty($_POST['pass']))
{
echo "all set! <br />";
}
else
{
echo "Not set up!";
trigger_error("Data Dump");
//dump all variables to the screen.
}
This script is only for testing. The above code works correctly, and identifies that everything is set and non null.
It gives the following Output:
User set
User not empty
Pass is set
Pass not empty
An error has occured in script /var/www/html/login.php on line 22: Data Dump
Date/Time: 12-13-2007 20:53:50
Array
(
[GLOBALS] => Array
RECURSION
[_POST] => Array
(
[user] => 12345
[pass] => 12345
[new] => Log In
)
However, if I comment out the first variable dump, then it will go directly to the else clause on the same input, and the variable dump shows that no vars are set.
How can commenting a variable dump change the behavior so much?
For clarity, here is the same code (one line commented) which does not work:
if (isset($_POST['user']))
echo "User set <br />";
if(!empty($_POST['user']))
echo "User not empty<br />";
if(isset($_POST['pass']))
echo "Pass is set<br />";
if(!empty($_POST['pass']))
echo "Pass not empty<br />";
[COLOR="Red"]//trigger_error("Data Dump");[/COLOR]//dump all variables on screen;
if (isset($_POST['user']) && !empty($_POST['user']) && isset($_POST['pass']) && !empty($_POST['pass']))
{
echo "all set! <br />";
}
else
{
echo "Not set up!";
trigger_error("Data Dump");
//dump all variables to the screen.
}
This version gives the following output:
Not set up!
An error has occured in script /var/www/html/login.php on line 82: Data Dump
Date/Time: 12-13-2007 20:56:10
Array
(
[GLOBALS] => Array
RECURSION
[_POST] => Array
(
)
Please Help!