Does anyone know whether I can removed a php session by using jquery or javascript?
3 Answers
"Regular" cookies can be deleted in JavaScript using something along these lines:
This function will "delete" the supplied cookie from the browser by setting the cookie's expiry date to one second in the past.
function delete_cookie ( cookie_name )
{
var cookie_date = new Date ( ); // current date & time
cookie_date.setTime ( cookie_date.getTime() - 1 );
document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}
If the cookie is a httpOnly cookie (a cookie with the httpOnly parameter set), you cannot read, change or delete it without closing the session (i.e. close the browser).
1 Comment
Christian Joudrey
In case the OP doesn't know, the session is stored server-side, but a cookie is stored client-side with the session id. Thus deleting this session id cookie will remove remove the session.