I have one PHP script with a session variable, set like so:
$_SESSION[\'VAR1\'] = \"test\"
Now, I am using AJAX via a jQuery-initiated POST
Make sure no content has been echoed (not even a whitespace) before calling session_start().
To be safe, put the code as the first code of whatever template you used for the page. The function will not work if content has been sent to the browser.
To test and see where the problem is, call the page as a stand-alone, instead of through AJAX and ensure that it works before AJAXing it.