php log out white screen occasionally

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


if (isset($_COOKIE[session_name()]))
   setcookie(session_name(), '', $cookie_expires, '/');

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


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?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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?
Dave BaldwinFixer of ProblemsCommented:
If the session is destroyed, then there are no valid $_SESSION[] variables.  That's probably the error.
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

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


Open in new window

Why is this?
petewinterAuthor Commented:
If I refresh the page afterwards session_destroy(); has cleared the $_SESSION["id"], but not on the same page load?
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.
petewinterAuthor Commented:
No I am outputting the $_SESSION["id"] after the session_destroy(); and it still outputs a result.
Dave BaldwinFixer of ProblemsCommented:
Please read this page for the proper way to use session_destroy().  If you use the code in Example #1, that won't happen anymore.
petewinterAuthor Commented:
Many thanks for your assistance.
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

From novice to tech pro — start learning today.