On Die command

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CerIs
Forum Newbie
Posts: 22
Joined: Sat May 29, 2004 9:20 am

On Die command

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

No you can't..

DIE terminates the script on that line.
Anything under it is skipped.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

why not just set the variable? why do you have to use die?
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

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