Session variable lost after setting it in ajax call In my custom .js code included into administration panel via my custom module I have AJAX call:

... //call this on click or sth
jQuery.post("sites/all/...mycustommodule/ajax/here.php", function(result){ alert(result); }


And here.php defines some custom session variable:

&lt;?php
sesssion_start();
$_SESSION['test_module_test'] = 'test';
echo $_SESSION['test_module_test'];
?&gt;


When I hit here.php with POST request thanks to my .js code I get alert with session variable outputed:


  test


But then, when I try to print_r($_SESSION['test_module_test']) inside my custom module code, I always get some session variables, but without my test_module_test:

Array 
( 
    [views_seed_time-...] =&gt; 1482412682 
    [views_seed_name-...] =&gt; 1482412682 
) 


I don't know if the session gets destroyed in between or there's something else going on here.
I'd assume those are 2 different sessions; use session_id()in both contexts to confirm.

To make sure you're using the same session, just implement your AJAX path inside Drupal, with hook_menu()