PHPできちんとセッション廃棄

セッション廃棄は気をつけようということで、session_destroy()だけでは不完全だよ、という教えです。

1.メモリ上のセッション情報を消す。
2.ブラウザのクッキーからセッションを消す。
3.セッションファイルを消す。

//1.メモリ上のセッション情報を消す。
$_SESSION = array();

//2.ブラウザのクッキーからセッションを消す。
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), ”, time()-42000, ‘/’);
}

//3.セッションファイルを消す。
session_destroy();

ブラウザのクッキーからセッションを消す、というのは気をつけていないと忘れそうですね。勉強になります!

関連する記事:

Powered by

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">