traq;11038983 wrote:
If there is state, it's not RESTful.
Using an api key actually ends up being the same thing in my opinion. There is state in both cases - refered to either by an api key or a session cookie. What I would care about is wether I have built-in cookie handling from where I issue my requests. But either way, I totally agree with you: do whatever makes sense with a minimum of fuzz for you and your users.
dalecosp;11038967 wrote:
I suppose the only thing I can think of it that there are two of them and perhaps it's getting confused? I know I sure am at this point π π
If there are two of them, you are probably setting (one of) them incorrectly at some point. For the cookie to be valid for both example.com, foo.example.com and www.example.com, you may need to use a . before the domain and leave the subdomains out.
.example.com
From the docs of [man]setcookie[/man]
path
The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.
domain
The domain that the cookie is available to. Setting the domain to 'www.example.com' will make the cookie available in the www subdomain and higher subdomains. Cookies available to a lower domain, such as 'example.com' will be available to higher subdomains, such as 'www.example.com'. Older browsers still implementing the deprecated Β» RFC 2109 may require a leading . to match all subdomains.
httponly would also screw things up, if the browser at hands respects this setting.
dalecosp;11039093 wrote:
The cookie appears in the headers, indeed. So, why doesn't the AJAX handler recognize this fact? π
The AJAX handler? I'm not sure I understand what part of the process you are talking about. Especially since I originally understood it as if the cookies where null server-side.
Cookies work in the following way. The server only sends cookie info when it wishes to set (including modify / delete) cookies. Moreover, a call to setcookie (server side) will NOT affect the $COOKIE array. The $COOKIE array is constructed from cookie header field data on incoming requests only.
The browser always sends all cookies - assuming valid settings for domain etc.
Time used to be an issue, and may still be in IE X (solve for x). Originally expiration was set as a fixed time. But with differing time zones, this leads to problems. Now you may specify duration instead, at least for newer browsers. So if your server and browser differ in opinions of time and you set expires with fixed time rather than duration, this will also have to be checked.
Other than that, the last thing that may cause problems is if you issue an ajax request to some OTHER sub(domain). In this case, you would have to resort to CORS - Cross Origin Resource Sharing. CORS will allow foo.example.com to send XHR, including cookie information, across domains, such as to bar.example.com. Iirc: GET/HEAD requests can be sent without pre-check if it includes proper CORS headers, while any request which (may) results in server side changes requires a pre-flight request to verify that the cross origin request is allowed.
But as far as the "AJAX handler" goes - when the response comes back from the server, the browser should update its cookie information as per the "set-cookie" header. Unchanged cookies should remained, unless they expired.
Things you may need to inspect
1. Does the browser send the cookie? Inspect the request from your browser
If no
- CORS or respect SOP (which includes port)
- may need to alter domain / path for which the cookie is valid when initially sent from server
- may need to set httponly
- may need https or disable "secure"
- Does the server accept the cookie? Inspect incoming http headers and inspect the cookie array.
If no:
- CORS is the only thing I can think of.
Does the server set the cookie? Use the browser to inspect the response. Is the proper information included in the set-cookie header?
Does the browser accept the incoming cookie, set it and subsequently send it?
I doubt this would break unless the cookie header is malformed.