开发者

Destroying Sessions in database with PHP

For a web application, I decided to store the sessions variables into a database. Everything is working like I want except for开发者_JAVA百科 the logout, in which I thought that with a simple session_destroy() will do the job but is not.

As I mention all the session information is stored in the database, but I notice that when calling session_destroy(); it does delete the session from the database but is not deleted from the server. I notice that if I do not close the browser, every time I loggin I get the same session id, therefore if I loggin with different username, I still get the same session id. How can I delete server session?

This is a function within a class that I use to destroy the session:

 function destroy( $id ) {

  // Build query
  $newid = mysql_real_escape_string($id);
  $sql = "DELETE FROM sessions_table WHERE session_id = '{$newid}'";

  mysql_query($sql);

  return TRUE;

}

Any advice please?


php-manual:

"session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called.

In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜