php log out white screen occasionally

php log out. I use the below php code to end a session and delete cookies.

session_start();

// IF THE SESSION IS KEPT IN COOKIE, FORCE SESSION COOKIE TO EXPIRE
if (isset($_COOKIE[session_name()]))
{
   setcookie(session_name(), '', $cookie_expires, '/');
}

if (isset($_COOKIE["superuser"]))
{
   setcookie("superuser", "", time() - 3600, '/');
}

session_destroy();
session_write_close();

Open in new window


However sometimes the html code after this does not load correctly. I get a blank screen. Sometimes it's fine and sometimes not. Any idea what could be causing this?
petewinterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Look at your error_log on that computer.  It should show the error that is causing that.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
petewinterAuthor Commented:
Thanks that has helped me, however it doesn't make sense as the error it refers to is within this code...

if(isset($_SESSION['id']) && !empty($_SESSION['id'])) {

// error here

}

Open in new window


The session should be destroyed so therefore the $_SESSION['id'] should not be set and the code should not run. Any idea's? I'm using chrome as my browser if that makes any difference?
0
Dave BaldwinFixer of ProblemsCommented:
If the session is destroyed, then there are no valid $_SESSION[] variables.  That's probably the error.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

petewinterAuthor Commented:
but if I output the $_SESSION["id"] on the page I get a result. The session has not been destroyed?

It does work though if I use the code below...

unset($_SESSION["id"]);

Open in new window


Why is this?
0
petewinterAuthor Commented:
If I refresh the page afterwards session_destroy(); has cleared the $_SESSION["id"], but not on the same page load?
0
Dave BaldwinFixer of ProblemsCommented:
That can depend on the order of the code.  If you access $_SESSION["id"] before doing session_destroy(); , then yes it will be in the page because it still existed when you referenced it.
0
petewinterAuthor Commented:
No I am outputting the $_SESSION["id"] after the session_destroy(); and it still outputs a result.
0
Dave BaldwinFixer of ProblemsCommented:
Please read this page http://php.net/manual/en/function.session-destroy.php for the proper way to use session_destroy().  If you use the code in Example #1, that won't happen anymore.
0
petewinterAuthor Commented:
Many thanks for your assistance.
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.