-2

Possible Duplicate:
proper way to logout from a session in PHP

I am using session_destroy for logout.Bt it destroys all the session so i found unset a particular session.What is the correct way? session_destroy() or unset(particularsession) for logout?

Community
  • 1
  • 1
jincy
  • 11
  • 1

3 Answers3

1

The best way is to destroy your session at the end of the php code using session_destroy()

h0lyalg0rithm
  • 150
  • 1
  • 6
0

It depends on your application, If you want to destroy all php sessions use session_destroy(). If you want to destroy a particular session use unset($_SESSION['name_here']).

Of course there are times when you may not want to destroy all session variables as they are not only used for logins and logouts. For that pupose you'll use unset($_SESSION['name_here`]).

Yousuf Memon
  • 4,638
  • 12
  • 41
  • 57
0

I use this piece of code to log somebody out:

<?php
    $_SESSION = array();
    session_destroy();
    unset($_SESSION);
    header('Location: '.ROOT_HREF.');
    die();
?>
Mathlight
  • 6,436
  • 17
  • 62
  • 107