Page 1 of 1

On Die command

Posted: Sat May 29, 2004 9:20 am
by CerIs
Can you set a variable on Die ? I was trying to do this

Code: Select all

<?php
if ("$Password_f" != "$Password_f2") 
die ($Message = 'Sorry the passwords do not match, please try again');
?>
and the later on i send the $Message to another page. But if you die the program stops so it wont excute the header later on to send it? Is there a way around this?

Posted: Sat May 29, 2004 9:54 am
by John Cartwright
No you can't..

DIE terminates the script on that line.
Anything under it is skipped.

Posted: Sat May 29, 2004 10:10 am
by Illusionist
why not just set the variable? why do you have to use die?

Posted: Sat May 29, 2004 1:02 pm
by scorphus
Yeah, just set the variable and latter call header()

Code: Select all

<?php
if ("$Password_f" != "$Password_f2")
   $Message = 'Sorry the passwords do not match, please try again';
else {
   // Do
   // stuff
}
// You might have other check routines...
header("Location: /anotherPage.php?Message=$Message");
die();
?>
Scorphus.