Jump to content

Error functions, die ()


Minimeallolla

Recommended Posts

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 >.<

Link to comment
https://forums.phpfreaks.com/topic/220457-error-functions-die/
Share on other sites

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? 

Link to comment
https://forums.phpfreaks.com/topic/220457-error-functions-die/#findComment-1142399
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.