Re: All Code Executing Even After header() Redirect

From: Date: Mon, 03 Mar 2003 20:07:06 +0000
Subject: Re: All Code Executing Even After header() Redirect
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-137958@lists.php.net to get a copy of this message
Add an exit statement after the header call. But I thought the same thing that after header nothing would be executed. if (!LoggedIn()) { // If not logged in, take to Login page. header("Location: /login.php"); exit(); } I just gave you this soultion to solve your problem, maybe someone else can shed some light why LogAccess() is executed. "Monty" <monty3@hotmail.com> wrote in message news:BA891C17.18C54%monty3@hotmail.com... > At the top of every page in my site I have a snippet of code that > authenticates the user by checking for valid SESSION vars and their > contents. If they don't, they are redirected with a header() statement to a > log-in page like this: > > include_once("function_library.php"); > session_start(); > > if (!LoggedIn()) { // If not logged in, take to Login page. > header("Location: /login.php"); > } > > LogAccess($_SESSION['user']); // This function logs user's access. > > > I noticed that the LogAccess() function I have after the header() redirect > is executing, even if the user is not logged in and is redirected to the > Log-In page. I did confirm that the LoggedIn() custom function is working > properly and returning the right value. > > I thought the code below the header() redirect would not actually be > executed unless the user was logged in and allowed to proceed. Is this how > PHP is supposed to work? Is there any way to prevent the script from > executing below a certain point if the user is not logged in? > > Thanks, > > Monty >

« previous php.general (#137958) next »