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

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
heiatufte
Forum Newbie
Posts: 18
Joined: Wed Mar 02, 2005 3:45 pm
Location: AA, Norway

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

Post 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?
Last edited by heiatufte on Wed Mar 02, 2005 5:59 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
thegreatone2176
Forum Contributor
Posts: 102
Joined: Sun Jul 11, 2004 1:27 pm

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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..
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi,

Maybe use return;
heiatufte
Forum Newbie
Posts: 18
Joined: Wed Mar 02, 2005 3:45 pm
Location: AA, Norway

Post 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]..?
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

Post by cbrian »

Near the top of your topic-starting post, it should say Edit. Click there and add [SOLVED] to the subject.
heiatufte
Forum Newbie
Posts: 18
Joined: Wed Mar 02, 2005 3:45 pm
Location: AA, Norway

Post by heiatufte »

Oh. How primitive.
Well, thanks...
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

Post by cbrian »

No problem.
Post Reply