Reputation: 663
Could someone explain me why when testing some PHP code on localhost warns with errors and uploading it on my hosting does not?
I find it disturbing, since is not the first time it happens, but seems like it works fine anyway...
Example:
Using a simple protect password in a single page:
<?php
// Define your username and password
$username = "logitek_00164";
$password = "JHvzQ3jK";
if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {
?>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="txtUsername">Username:</label>
<input type="text" title="Enter your Username" name="txtUsername" />
<label for="txtpassword">Password:</label>
<input type="password" title="Enter your password" name="txtPassword" />
<input type="submit" name="Submit" value="Login" />
</form>
Reports this error: Notice: Undefined index: txtUsername in C:\xampp\htdocs\test_password\index.php on line 6
I know that reporting errors OFF could be a solution (the worst one), and in the other hand, I could solve the problem, but I am just wondering if the problem comes by some PHP configuration or not.
Thank you in advance
Upvotes: 0
Views: 217
Reputation: 2704
You should use:
if ((isset($_POST['txtUsername'])&&$_POST['txtUsername'] != $username )|| (isset($_POST['txtUsername'])&&$_POST['txtPassword'] != $password)) {
Well error reporting is also configured in php.ini
you can disable(I wont recommend in development) from there.
Upvotes: 0
Reputation: 1103
Because php in XAMPP is configured like that in php.ini and php on your server isn't.
See http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
It can also be configured inside your php script. See http://php.net/manual/en/function.error-reporting.php
Upvotes: 1