AndrewM16921 Posted June 4, 2013 Share Posted June 4, 2013 Hey so, I'm trying to get a php session to work with ajax calls from jquery. It doesn't seem to be working, so I'm guessing something like a session id isn't getting sent by the ajax calls. Not sure how to fix this. Googled some stuff, wasn't entirely sure what to make of it all. I'll post some examples I whipped up to test it. Pretty simplistic example. The js below gets "info.php", which should return a couple spans, the first of which (for testing sake) should just increment each time it's called. $(function(){ $("#sp-info").load("info.php");} <?php session_start(); if(isset($_SESSION["uid"])) { $_SESSION["uid"] = 1; } else { $_SESSION["uid"] = $_SESSION["uid"] + 1; }?><span id="info-left"> Welcome, <? echo $_SESSION["uid"]; ?>!</span> Link to comment Share on other sites More sharing options...
justsomeguy Posted June 4, 2013 Share Posted June 4, 2013 Don't start the session for the first time in the ajax call, start the session on the parent page first so that they have their session cookie already by the time they start sending ajax requests. Link to comment Share on other sites More sharing options...
AndrewM16921 Posted June 4, 2013 Author Share Posted June 4, 2013 Actually, I just fixed the problem. Stupid mistake! Instead of if(isset($_SESSION["uid"])) I forgot to negate it if(!isset($_SESSION["uid"])) But thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now