开发者

PHP session var strange value through AJAX

my code is a bit messy so I'll try to explain to you in words:

I 开发者_StackOverflow中文版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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜