php - Deleting session variables in Safari causing errors -
i have 3 variables in $_session array: "views", "user_id", , "username". when user logs out, "user_id" , "username" deleted. works fine in browsers, , in safari 75% of time. sometimes, instead of deleting variables, gives value "deleted" variable. throws whole site off because it's based on whether variable defined or not.
my code delete variables is:
unset($_session["user_id"]); unset($_session["username"]); $_session = array(); session_destroy(); and in safari, var_dump($_session) gives:
... ["user_id"] => string(7) "deleted" ["username"] => string(7) "deleted" ... any ideas why safari doing this?
safari has nil problem. sessions managed on server side , safari (or browser) has holding cookie phpsessid inside.
your problem due session_destroy. (emphasis mine)
session_destroy() destroys of info associated current session. it not unset of global variables associated session, or unset session cookie. utilize session variables again, session_start() has called.
in order kill session altogether, log user out, session id must unset. if cookie used propagate session id (default behavior), session cookie must deleted. setcookie() may used that.
your unset() phone call should trick themselves. , can combine them
unset($_session["user_id"], $_session["username"]); try adding session_write_close(); , see if makes difference.
failing that, seek expiring session cookie
$params = session_get_cookie_params(); setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"] ); php session session-variables
No comments:
Post a Comment