Cookies sent/received between jQuery Ajax and PHP
Posted on 2011-10-07
I am working on an Ajax application that uses jQuery to send requests to PHP scripts. After typing his credentials in, the user hits the "Sign In" button, which sends his credentials to a PHP script that either starts his session and puts the key into a cookie and prints out JSON-encoded "true", or prints out JSON-encoded "false." The cookie is successfully loaded into the browser, and appears correct when viewed in Firecookie.
No problem so far. However, when I attempt to then make another AJAX request and continue the session, it does not appear that the cookie (which is set to last for half an hour currently, but its lifetime will be refreshed as long as the user continues working) is being sent properly by jQuery Ajax. Opening up my request in the Firebug console, the cookie sent has the same value, but is lacking its "domain", "path", and "expires" attributes.
This seems to result in my PHP not behaving correctly, as it is not pulling previous session information out of the database because it thinks it doesn't have the right cookie (because it is missing essential data). However, a new cookie is not created by "session_start."