简体   繁体   中英

PHP session variables and jQuery

So, I've got a bit of an issue handling PHP session variables. I've got a jQuery function to post the variable to a PHP file (working, see code here):

   $('#practiceid').blur(function() {
    var practiceid = $(this).val();
    $.post("delicious.php", {"pid": practiceid});
   });

Thanks to Firebug I can see that delicious.php receives the variable. Now, the code in that PHP file is:

$_SESSION['uploaddir'] = $_POST['pid'];

The issue now is that when I try to use the session variable in other PHP files it just seems not to exist. I've declared the session_start(); in the index.php file.

Any ideas?

Thanks so much.

您确定要在每个需要使用$ _SESSION成员的页面上调用session_start()吗?

session_start() needs to be written on every page where you are using session values.

Also, don't directly assign values to SESSION variable. USe this :-

if(isset($SESSION['uploaddir'])){
 unset($_SESSION['uploaddir']); 
} 
$_SESSION['uploaddir'] = $_POST['pid'];

The assignment you used may lead to warnings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM