Ad

Query URL For Log In Status, Javascript

- 1 answer

This may seem like a no-brainer, but I can't find a way to do this that isn't considered a security issue (other than the obvious ways)...

So, I want to build an add-on for Firefox to use with my team. Basically it will be a status bar icon letting us know if the authentication cookie for our tools site has expired, so we can tell without losing any work currently in the browser.

At first I thought I could have the add-on check the cookie, but this seems to be a huge hassle for such a simple idea. Then it occurred to me...DUH...that I could just have the add on try to access the main page of our site. If it gets a "Access Denied" response, it can show the icon for "Not Logged In", but if it gets anything else, it can show "Signed In".

However, all attempts to do this with AJAX are proving to be almost as difficult as my cookie attempts.

Is there a simple way, with javascript preferably, but in XUL otherwise, to say

var url = "http://example.com";
var response = pingURL(url, "blah);
status = (response = "Welcome!") ? "Signed in" : "Not Signed In";

where "pingURL" would be the method of "going" to the url and getting the response?

Ad

Answer

Exactly why do you consider cookies a huge hassle? That would undoubtedly be faster and probably simpler to implement. Reading cookies from chrome is simple and well-documented. Ask for help if you can't figure out how to parse the cookie.

Ad
source: stackoverflow.com
Ad