i build a website and it has a sign in form, when user sign in, the sign in form will not appear, and a sign out will apprear instead
my problem is when the user sign out the session doesn’t destroy
when user sign in , i got to the function run, when user sign out i go to the function sign out
HTML
<?php
Session::init();
$l = Session::get('loggedIn');
if (isset($l) && $l==true) {
?>
<a href="<?php echo URL; ?>login/signout" class="smallLink">sign out</a>
<?php
} else {
?>
<a href="login/run">Sign in</a>
<br/>
<form action="<?php echo URL;?>login/run" method="POST">
<div class="staticSignin">
phoneNumber
password
</div>
<div id="userInputSignin">
<input type="text" name="MNumber"/>
<input type="password" name="password"/>
<input type="image" src="http://localhost/Mar7ba/public/images/signinButton.png"/>
</div>
</form>
<?php
}
?>
run for sign in
Session::init();
$row = $sth->fetch();
$ID = $row['ID'];
$rollID = $row['rollID'];
Session::set('loggedIn', true);
Session::set('ID', $ID);
Session::set('roolOfUser', $rollID);
sign out
public function signout() {
Session::set("loggedIn", false);
Session::destroy();
$this->view->render('index/index');
}
Session Class
<?php
class Session {
public static function init() {
session_start();
}
public static function set($key, $value) {
@$_SESSION[$key] = $value;
}
public static function get($key) {
if (isset($_SESSION[$key]))
return $_SESSION[$key];
}
public static function destroy() {
unset ($_SESSION);
session_destroy();
}
}
when sign out , the sign in form doesn’t appear
To destroy a session you need first to start it using
session_start(), seems that you aren’t doing thisTry to do it:
EDIT 1
Try to do these changes in
destroy()to test if the session is really being started: