rocoso Posted May 26, 2008 Share Posted May 26, 2008 Hi phpfreaks!! Ive been wondering... Sometimes i get "Notice: Undefined variable: .... " I usually do a error_reporting(0); or define it like $blabla = ""; somewhere in the beginning of my script. How bad is a Undefinded variable ? The script still works. I just dont want no errors at all. Quote Link to comment https://forums.phpfreaks.com/topic/107275-notice-undefined-variable-bla-bla/ Share on other sites More sharing options...
Barand Posted May 26, 2008 Share Posted May 26, 2008 At best, it's bad programming practice to reference variables that haven't been initialised. At worst, your script won't work. See trivial example below. I recommend you use error_reporting(E_ALL) when developing you scripts. Example <?php include 'db.php'; error_reporting(E_ALL); if (isset($_POST['username'])) { $username = $_POST['username']; $password = $_POST['password']; $sql = "SELECT password FROM users WHERE username = '$username'"; $res = mysql_query($sql); if ($row = mysql_fetch_row($res)) { if ($pasword == $row[0]) // undefined variable - never logs in { exit("Login successful"); } } } ?> <form method='post'> Username <input type="text" name="username" size="12"> <br> Password <input type="text" name="password" size="12"> <br> <input type="submit" name="btnSubmit" value="Log in"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/107275-notice-undefined-variable-bla-bla/#findComment-550089 Share on other sites More sharing options...
Daniel0 Posted May 26, 2008 Share Posted May 26, 2008 At worst, your script won't work. See trivial example below. I recommend you use error_reporting(E_ALL) when developing you scripts. And turn them off when the script is running on a live site. Expose as little information as possible to potential attackers. Quote Link to comment https://forums.phpfreaks.com/topic/107275-notice-undefined-variable-bla-bla/#findComment-550130 Share on other sites More sharing options...
PFMaBiSmAd Posted May 26, 2008 Share Posted May 26, 2008 The display_errors setting should be used on a live server to prevent the display of errors, but error_reporting should be left as E_ALL. This still allows error logging to show unexpected conditions, such as un-caught conditions with data verification that you might need to address in your code (maybe a search script keeps failing because commonly entered values are causing notices/warnings) or things like a hacker submitting deliberately invalid data to your script to see if he can break in. When warnings or notices are disabled, you don't have any record of what went wrong. Quote Link to comment https://forums.phpfreaks.com/topic/107275-notice-undefined-variable-bla-bla/#findComment-550229 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.