Reputation: 1
my code is a bit messy so I'll try to explain to you in words:
I have this index.php page that shows a random file from my files table in my database. People have the opportunity to rate these files by clicking on notes that open "vote.php" through a small AJAX pop-up.
Now here's the problem. On index.php I pull the ID from the database and output it:
$_SESSION['file_id'] = $file_id;
echo $_SESSION['file_id'];
But when I open the vote.php pop-up and write:
session_start();
echo "SID="; echo $_SESSION['file_id'];
The value is not the same! What could cause this?
Thank you very much.
Upvotes: 0
Views: 277
Reputation: 41
You shall pass sessions variables to your AJAX requests in the form of (javascript code):
enquiry.php?' + session_name + '=' + session_id + '&vote=whaevere_you_want&foo=bar
Where session_name and session_id are javascript local variables obtained via AJAX initalizer to fetch them from a php script which is capable of providing them via PHP functions:
session_name()
session_id()
respectively
Upvotes: 0
Reputation: 7750
Without fixing this specific problem, I don't think $_SESSION
is needed here.
Can't you open vote.php
with
vote.php?file_id=xxxx
You just need to add the variable in the URL when you generate index.php.
No need for sessions here.
Upvotes: 1