Page 1 of 1

exit() in an include?

Posted: Wed Mar 04, 2009 5:02 pm
by andym01480
If i have an

Code: Select all

if($foo=='bar'){
header("Location:somewhere-else.php");
exit();
}
in an included script does that just stop executing the include script or the script that included it too?
Kaisell's got me worried! (From a topic a few weeks ago that popped in my head again)

Re: exit() in an include?

Posted: Wed Mar 04, 2009 6:10 pm
by atonalpanic
I believe it stops everything, but you can try it yourself with something like:

test.php

Code: Select all

 
<?php
require "other.php";
echo "Execution continues.";
?>
 
other.php

Code: Select all

 
<?php
exit();
?>
 

Re: exit() in an include?

Posted: Thu Mar 05, 2009 1:50 am
by andym01480
Looks like it in a browser - what about hacker tools?

Re: exit() in an include?

Posted: Thu Mar 05, 2009 1:55 am
by Benjamin
exit() and die() both halt all script execution for the current request.

Re: exit() in an include?

Posted: Thu Mar 05, 2009 2:18 am
by andym01480
Thanks is the current request the include or the script that included it?

Re: exit() in an include?

Posted: Thu Mar 05, 2009 2:51 am
by Benjamin
Both.

If you only want to halt execution of an included file you can use return;

Re: exit() in an include?

Posted: Thu Mar 05, 2009 4:13 pm
by kaisellgren
andym01480 wrote:If i have an

Code: Select all

if($foo=='bar'){
header("Location:somewhere-else.php");
exit();
}
in an included script does that just stop executing the include script or the script that included it too?
It stops them both.