Why exit doesn't reset the Session.

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
Redorc
Forum Newbie
Posts: 2
Joined: Tue Dec 21, 2010 7:27 am

Why exit doesn't reset the Session.

Post by Redorc »

Hi, I have a problem with a redirection. I want to redirect with the header function(), but if i use this function my $_SESSION is resetted.
Code:
header('Location: index.php' );

I have found a solution, if i write exit () after the header() my $_SESSION isn't resetted.
Does anyone know why?
Thanks :D
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Why exit doesn't reset the Session.

Post by Darhazer »

If you do not put exit; after the redirect, the rest of the code will be executed.
Browser also can bypass the redirect header, so the user can see the page.

Most likely there is some code after the header() function that resets the session (but terminating the execution with exit; does not allow it to be executed)
Redorc
Forum Newbie
Posts: 2
Joined: Tue Dec 21, 2010 7:27 am

Re: Why exit doesn't reset the Session.

Post by Redorc »

If you do not put exit; after the redirect, the rest of the code will be executed.
I didn't know this 8O I don't like it but i can handle :)
Thanks a lot for the help :D :drunk:
Post Reply