Why can't I access session variables from my AJAX-called PHP script?

前端 未结 7 1978
情话喂你
情话喂你 2021-01-11 11:03

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

7条回答
  •  不知归路
    2021-01-11 11:40

    Make sure that the domain names for both pages (i.e. the AJAX container and the AJAX script are same). Here is an example:

    http://mydomain.com/login.php           (set session variables here)
    http://mydomain.com/ajax-container.php  (session variables are visible here)
    http://mydomain.com/ajax-script.php     (session variables are visible here)
    http://www.mydomain.com/ajax-script.php (session variables are NOT visible here)
    

    Another one:

    http://www.mydomain.com/login.php          (set session variables here)
    http://www.mydomain.com/ajax-container.php (session variables are visible here)
    http://www.mydomain.com/ajax-script.php    (session variables are visible here)
    http://mydomain.com/ajax-script.php        (session variables are NOT visible here)
    

提交回复
热议问题