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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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