Trouble with 2 session_id()'s on my site - PHP/Jquery
<p>I'm trying to build a site that runs without refreshes, using Jquery and PHP to populate divs that slide in/out. basics work OK, but I am having trouble passing session values around. </p>

<p>I have a login panel first that captures "$user" in PHP and then stores is as a session variable $_SESSION['user']. </p>

<p>I can then use it on the first page OK (the first page gets written by index.php.)
Subsequent pages are called by Jquery, like:</p>

<pre><code>$(".scrollclick").click(function () {
var show = this.getAttribute("id");
$("#page2content").load("showpage2.php?show="+ show);
$("#homepagecontent").hide("slide", { direction: "left" }, 1000);
$("#page2content").css("visibility","visible");           
$("#page2content").show("slide", { direction: "right" }, 1000); 
</code></pre>

<p>where the variable "show" comes from a clickable div image name. Again all works fine.</p>

<p>However, the problem is that somehow the session variables are not the same in the other PHP page's that get loaded, after the initial home page load.</p>

<p>I know to use session_start(); at the top of each PHP script and I've echo'ed the session_id() to prove that sessions are working and that strangely the session ids are different.</p>

<p>I've even got other scripts populating the session variables quite happily in the other scripts. </p>

<p>I seem to have proved that every other PHP script on the site creates pages with the SAME session id, except the home page which holds a different one. Trouble is, that it's the home page session that holds the "user" variable that I want to propagate.</p>

<p>I've tested it in Chrome, IE and FF. All the same. Result is two session id's - one for the home page and one for all the others.</p>

<p>I am guessing that there's something in one of the other pages that is somehow flushing the session, like session_write_close() but I can't find it.  I've created the site using a couple of ready made (great) scripts (Jquery chat, tutorialzine login demo), so they might be playing around.</p>

<p>I have just today set up a couple of dummy pages that do roughly the same thing and they work OK, so there HAS to be a really dumb mistake somewhere!!!</p>

<p>Possible workaround?</p>

<p>I even tried finding a way to manually propagate the userid across the PHP calls, but struggled to get the variables into Javascript (for the jquery calls) [I can get this to work OK] and then back into the PHP?user=xxxx string so that I can _GET it back at the other end. [can't get this to work]</p>

<p>I've seen some advice that suggests using:</p>

<pre><code>var username = &lt;?php echo $user;?&gt;;
</code></pre>

<p>Some suggest quotes, some don't. With quotes, it's just interpreted as a string, without it seems to just stop the javascript dead in its tracks</p>

<p>Does anyone have any pointers to either the sessions issue or the variables workaround ??</p>

<p>The site structure is all flat btw, all (most) in one directory in one domain.</p>

<p>Ever grateful! (as someone who's now wasted 3 days going round in circles)</p>

<p>TonyJ</p>
