0

I have a small website using a session to check for an user login.

When the user click logout the are being redirected to a page containing only session destroy.

The code is as followed:

<?php
session_start();
if(session_destroy()) {
    $_SESSION = array();
    header("Location: http://domain.com/");
}
exit();
?>

I've tried to remove the if statement to check for any problem when destroying the session.

I have even used unset and setting the array to empty.

Still when redirected to the domain homepage the user is still logged in and the session is still set.

Also i tried to unset the specific session and still nothing happens.

-- Update: The session is not even being return as an empty value. Echoing the session after logout still returns the value of the username.

LetMeAnswerThis
  • 129
  • 3
  • 11

2 Answers2

0

This answer should help. As Roland Starke mentioned in a comment, session_destroy will not remove a cookie.

https://stackoverflow.com/a/3512570/3563178

Community
  • 1
  • 1
Tim
  • 176
  • 1
  • 15
  • It was simply a spelling mistake. Not working with cookies on the website at all. I'm simply meaning session. Also using the code provided in the forum or the from the original post on .php i simply receive a 500 internal error. i believe this is because i have no access for the .ini file. – LetMeAnswerThis Nov 18 '15 at 11:50
0

try this.

<?php
session_start();
if(session_destroy()) {
echo '<meta http-equiv="refresh" content="0;URL=http://domain.com">';
}
exit();
?>

I think the header is throwing an error in this particular case of yours. hmmmm.....(Header already sent)...

Mark Ng
  • 200
  • 3
  • 11