exit() in an include?

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

exit() in an include?

Post 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)
atonalpanic
Forum Commoner
Posts: 29
Joined: Mon Mar 02, 2009 10:20 pm

Re: exit() in an include?

Post 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();
?>
 
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: exit() in an include?

Post by andym01480 »

Looks like it in a browser - what about hacker tools?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: exit() in an include?

Post by Benjamin »

exit() and die() both halt all script execution for the current request.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: exit() in an include?

Post by andym01480 »

Thanks is the current request the include or the script that included it?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: exit() in an include?

Post by Benjamin »

Both.

If you only want to halt execution of an included file you can use return;
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: exit() in an include?

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