Results 1 to 4 of 4

Thread: Help with DIE and EXIT please!?

  1. #1
    Join Date
    Sep 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with DIE and EXIT please!?

    Hi,

    First post here, so want to say hello to everyone.

    I know this is bad form, first post asking a question, but I thought I may as well get down to it...

    I am quite new to PHP andhave a query I hope someone can help me resolve.

    I am coding a Change Password routine and am having differing results with error handling. Basically, if a user enters an incorrect password, when I run the following code:

    Code:
    {
      header("Location: change_password.php"); 
      exit("New Passwords do not match.");
    }
    nothing really happens except the three "password" textboxes get cleared and the process starts again. This is fine, but there is no feedback to the user telling them they have entered an incorrect stored password. Similar happens when they enter new passwords that do not match.

    So, to try to give them some feedback, I tried this code instead:

    Code:
    {
      print '<script type="text/javascript">'; 
      print 'alert("The new Passwords entered do not match.")'; 
      print '</script>'; 
      header("Location: change_password.php"); 
      exit("New Passwords do not match.");
    }
    what happens now is they get an alert box informing them of their error, but once I click "Ok" the program stops altogether and the screen clears, then the error description in the exit statement is printed.

    Can anyone help please!

    Thanks

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Oh yeah, this is not a hard and fast rule. But you almost never can use a header after you have written to the page. You could use javascript to change the location of the page:

    PHP Code:
    {
      print 
    '<script type="text/javascript">'
      print 
    'alert("The new Passwords entered do not match.");'
      print 
    'window.location.replace("change_password.php");'
      print 
    '</script>'
      print 
    '<noscript>'
      print 
    'The new Passwords entered do not match.<br>'
      print 
    '<a href="change_password.php">Try again</a>'
      print 
    '</noscript>'
      exit(
    "New Passwords do not match.");

    There could be a better way. How did we get here? In PHP, it generally wouldn't know until you submitted the page. But javascript could check this and some other things before submitting.
    Last edited by jscheuer1; 09-06-2014 at 02:56 PM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Sep 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    @mloclam you can't use header after print command.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This is getting to be an older thread, so I'm closing it. If anyone wants to continue the discussion, feel free to start a new thread and refer back to this one.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Pause flv player on exit pop
    By edwardlarson in forum HTML
    Replies: 0
    Last Post: 03-10-2009, 04:53 AM
  2. Trouble with an exit popup.
    By Droogie in forum Looking for such a script or service
    Replies: 4
    Last Post: 01-16-2009, 04:23 AM
  3. Message on page exit...
    By rhiaro in forum Looking for such a script or service
    Replies: 3
    Last Post: 06-09-2008, 05:03 AM
  4. How to exit frameset?
    By ez_going in forum HTML
    Replies: 4
    Last Post: 12-12-2007, 08:58 PM
  5. Exit Thank you
    By shahafin in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 02-14-2005, 12:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •