Is it by any means possible to read the browser session id using javascript?
+6
A:
Yes. As the session ID is either transported over the URL (document.location.href
) or via a cookie (document.cookie
), you could check both for the presence of a session ID.
Gumbo
2009-05-28 12:53:31
sarnath'd damn you :) Also worth mentioning some platforms write this out to a hidden field in a retrievable, determinable way.
annakata
2009-05-28 12:54:48
+4
A:
As far as I know, a browser session doesn't have an id.
If you mean the server session, that is usually stored in a cookie. The cookie that ASP.NET stores, for example, is named "ASP.NET_SessionId".
Guffa
2009-05-28 12:55:50
A:
hi. you can receive the session id by issuing the following regular expression on document.cookie:
alert(document.cookie.match(/PHPSESSID=[^;]+/));
in my example the cookie name to store session id is PHPSESSID (php server), just replace the PHPSESSID with the cookie name that holds the session id. (configurable by the web server)
ufk
2010-01-11 16:18:25