How make PHP session work using subdomain and AJAX?
<p>I'm working in a PHP project that uses subdomains, sessions and Ajax. But unfortunately I can't make it work!  I'll try explain:</p>

<p>Let's assume that I'm at this domain: <strong>app.mysite.com/index.php</strong></p>

<p>At this domain, I have a form that performs an Ajax request to <strong>mysite.com/functions/execute.php</strong> (without any subdomain)</p>

<p>In the first line of <strong>execute.php</strong>, I have a <strong>require_once</strong> that include a <strong>helper.php</strong> file. In this file I have put:</p>

<pre><code>ini_set('session.cookie_domain',  '.mysite.com');
session_set_cookie_params(0, '/', '.mysite.com');
session_start();
</code></pre>

<p>All PHP files listed also include the helper.php.</p>

<p>If I for example run:</p>

<pre><code>echo $_SESSION["myValue"];
</code></pre>

<p>At <strong>app.mysite.com/index.php</strong> or any other subdomain, like <strong>auth.mysite.com</strong>, I'll get the value: <strong>"test"</strong>.
But if I run the same code at <strong>execute.php</strong>, and return the value through Ajax I'll get undefined index!</p>

<p>What am I doing wrong?</p>