Just wondering if it’s possible to use an XMLHTTPReq to login to a website, and store the cookie. Specifically I’m after the PHPSessionID from the website I am logging into.
I then want to pass this cookie into another request to submit a form.
Any ideas of how to do this?
Cheers,
Nick
You will be able to get your own site’s cookies from
document.cookie. In the AJAX callback, use a library to parse the value and read the cookie you’re looking for.Of course, if the server sets the cookie
HttpOnly(which it should be doing), it won’t be available indocument.cookie.At this pont, you need to reevaluate what you’re doing:
If you’re logging in to another site, then no – the same-origin policy prevents you from accessing another site’s cookies.
Edit: Since this is for your own use, you can do this in a way you’re not limited by the browser’s origin restrictions. Some thoughts:
POSTto the login page, get theSet-Cookieheader in the response, and use it to send aCookieheader in anotherPOSTto the form target.