Page 1 of 1

[SOLVED] die() and exit() stopping html code?

Posted: Wed Mar 02, 2005 4:19 pm
by heiatufte
Hi!
I have a login on my site and I use a checkuser() function everytime the user opens a site where you have to be logged in. So the scripts runs the checkuser function and if the session username/password is wrong, it echos a message, and on the end it runs "exit();" so it doesn't show the rest of the code in the original admin-site file. My problem is that it "stops" the whole site, when the exit(); is executed the server stops sending the rest of the html file. I only want the php code to stop executing, because this is in the middle of a table and the site and error message doesn't look good when it isn't closed. Do you have any tips how to make that possible?

Posted: Wed Mar 02, 2005 4:23 pm
by feyd
use flow control structures.. for instance:

Code: Select all

if(isAdmin($user,$password))
{
  // show admin stuff
}
else
{
  // drop kick the user
}
isAdmin would return a false type value when the user isn't an admin..

Posted: Wed Mar 02, 2005 4:25 pm
by thegreatone2176
this would be very easy if you are using an include for the table and if you are you could just do

Code: Select all

/*after false info*/
echo "Invalid Info";
include("lefttable.html");
die;
so basically just print the invalid message then include the table so the pages displays properly then end the code

Posted: Wed Mar 02, 2005 4:25 pm
by onion2k
If you're in a loop then you can use break(); to get out of it. If you've got a series of statements to run, enclose them in an if{ } block, and set a variable such as $stop = 1 .. and have if ($stop==0) { } surrounding the rest of the PHP code. Theres no way to only stop the PHP.. exit() stops everything..

Posted: Wed Mar 02, 2005 5:04 pm
by Jim_Bo
Hi,

Maybe use return;

Posted: Wed Mar 02, 2005 5:51 pm
by heiatufte
Wow! Thanks for the replies, the first 3 came within 6 minutes, that was incredible..! I think I'll like it here at this forum :D
I decided that the footer or lefttable.html include would be the easiest to make, and would require less changes on the original code than the others. But by all means, thanks for your suggestions!
How do I mark the thread [SOLVED]..?

Posted: Wed Mar 02, 2005 5:58 pm
by cbrian
Near the top of your topic-starting post, it should say Edit. Click there and add [SOLVED] to the subject.

Posted: Wed Mar 02, 2005 6:00 pm
by heiatufte
Oh. How primitive.
Well, thanks...

Posted: Wed Mar 02, 2005 6:01 pm
by cbrian
No problem.