Minimeallolla Posted December 2, 2010 Share Posted December 2, 2010 I have a login code that uses die() and when the die code is executed it terminates the rest of the html code. I cant put the html before the php because of meta tag and head tag issues >.< I need a proper working error function that works properly \= like if you login wrong on myspace or facebook a little error message appears in a box and works perfectly. On mine it appears at the bottom of the form and cuts of teh rest of the source code and html >.< Quote Link to comment Share on other sites More sharing options...
gizmola Posted December 2, 2010 Share Posted December 2, 2010 Don't use die. The use of sessions can solve your issues. Quote Link to comment Share on other sites More sharing options...
Minimeallolla Posted December 2, 2010 Author Share Posted December 2, 2010 no i mean like if username password != blabla die message appears. Quote Link to comment Share on other sites More sharing options...
gizmola Posted December 2, 2010 Share Posted December 2, 2010 Yes, I understand what you meant. You should not use die. You can perform your error checking at the top of the script based on whatever conditions represent errors. If there are errors, you can either redirect or you can simply display the errors in a box and re-emit the form. This is a pretty standard problem and easy enough to code for. Your first problem is that you are using die(). What many people will do is create an array called $errors. If your error checking code finds an error you add to the $errors array. // .... some error occurred $errors[] = 'The user was not found or the password did not match. Please check your input and try again."; Then you can check to see if there were any errors: if (count($errors) > 0) { // Login form needs to be shown again // Show error box now foreach($errors as $msg) { echo $msg; } } These are very simple examples that leave off obvious condition checking. Your code didn't have any setting of state to indicate that a person was successfully logged in. This is something that shoudl be checked, because people shouldn't be seeing a login form if they have already logged in. How are you going to handle that if you don't use sessions? Quote Link to comment 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.