title: Create cross subdomain cookies/sessions with AngularJS & PHP
body: <p>My app has the following structure: there's the front-end js app (angular) on the <code>app.</code> subdomain and a backend (PHP) on the root and <code>api.</code> subdomain. My login is done via the root which stores a session cookie. The cookie is stored for all subdomains with the path "/".</p>
  
  <p>Directly on the api I can get the cookie. However on the same url but via an ajax GET call from the front-end the cookie is NULL.</p>
  
  <p>But using an application like Postman (chrome app) a GET request to the same URL and I can get the cookie. So it seems to be specific to my apps frontend.</p>
  
  <p>Here are my settings for my angular app. I've set these defaults in my app config:</p>
  
  <pre><code>$httpProvider.defaults.useXDomain = true;
  $httpProvider.defaults.withCredentials = true;
  delete $httpProvider.defaults.headers.common['X-Requested-With'];
  </code></pre>
  
  <p>I've tested on both Chrome and FF. Can't figure out why my cookies/sessions are unavailable between my frontend and backend</p>
  
  <p><strong>Update 20/11/2013</strong></p>
  
  <p>I also had a problem specifically with the version Angular I was using. Because I was using <code>$resource</code> instead of just <code>$http</code>, that version of angular wasn't attaching the <code>withCredentials</code> setting to the http request when using <code>$resource</code>. Updating to the latest angularjs version has fixed my problem. Because the withCredentials was not being set my cookies weren't being sent along with the xhr request. Stupidly I hadn't checked if cookies were being sent.</p>