AJAX with PHP Sessions

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]

<?php session_start(); if(isset($_SESSION["uid"])) { $_SESSION["uid"] = 1; } else { $_SESSION["uid"] = $_SESSION["uid"] + 1; } ?> Welcome, <? echo $_SESSION["uid"]; ?>! Login | Register [/php]

Nvm, stupid mistake… lol

Instead of

if(isset($_SESSION[“uid”]))

I forgot to negate it :stuck_out_tongue:

if(!isset($_SESSION[“uid”]))

Sponsor our Newsletter | Privacy Policy | Terms of Service