Page 1 of 1

please help me understand this code for logging out

Posted: Sat Feb 11, 2012 5:19 pm
by username0
Someone gave me this script for logging out the user and redirect to another page:

Code: Select all

<?php
ob_start();
$_SESSION = array();
// invalidate session cookie
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-86400, '/');
}
// end session then redirect
session_destroy();
header('Location: /index.php');
ob_flush();
exit;
?>
I'm not sure about the purpose of ob_start() and ob_flush().
Also, why $_SESSION = array()?
Thanks.

Re: please help me understand this code for logging out

Posted: Sun Feb 12, 2012 3:31 pm
by social_experiment
$_SESSION = array() sets the $_SESSION variable to an empty array so everything is 'unset' (all session variables are destroyed);

http://www.php.net/manual/en/function.ob-flush.php
Have a look at the php manual re ob_flush() and ob_start(); I have a vague idea about what they do but not enough to tell you with certainty