Reputation: 6981
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.
Upvotes: 1
Views: 1929
Reputation: 3793
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
Upvotes: 0
Reputation: 2948
Did you make sure session_start() is called on every page that needs to use the $_SESSION member?
Upvotes: 5