I'm building a deeplink system into a very complex website which needs cookies and other context set-up before the deeplink will work (otherwise the page gets redirected back to the home page - not much use).
So I've added a module which provides the deeplink entry point through hook_menu:
deeplink/<deeplink-parameters>
The callback builds the context, adds the cookies and then redirects to the actual required page.
So much for the theory. It doesn't work and I can't figure out why not.
In order to replicate a completely "virgin" request I've been using incognito windows, restarting the server and clearing caches before each test. In the test version I'm not redirecting to a new page, just outputting a line of text to display the page.
But even attempting to generate a simple test cookie with a long life (REQUEST_TIME + 999999) fails. No cookie created. The setcookie() function is returning TRUE (cookie created), which implies there is no problem.
The only cookies I can see are the ones created by JavaScript on the page itself, and a couple created by the Zeus wrapper (there are no Zeus rules to delete cookies on standard Drupal pages).
Just in case the cookie isn't visible on the first page I am also then moving to another page but still no cookie. Seems like it just isn't being created despite what the function says.
Additional data: There is also no PHP Session ID cookie.
Any thoughts as to why the cookies are not appearing?
EDIT: Looking at this further, I moved the setcookie() function into index.php (before the Drupal bootstrap), and it still wasn't creating the cookie.
So rather than issuing the deeplink command as above I simply went to the home page. And it's still not creating the cookie (as an anonymous user, with everything cleared before we start).
Only when I moved away and into the more complex part of the site did the test cookie appear. At the same time that the PHP Session ID cookie appeared. Is this a hidden dependency? No cookies can be created through PHP unless there's a PHP session ID?