开发者

edit $_SESSION with JS call

Hello I have a script that uploads multiple images (this script is c开发者_JAVA技巧omposed of many steps so I need to keep data through it). The upload is composed by a JQuery script that calls a PHP function to save images to a directory. On this script I added this line

$_SESSION["login"]["auth"]["images"][] = $file_name;

that should add every image file name added to that array, but the $_SESSION variable remains untouched. I can't change the $_SESSION from JS calls?


No, you can't modify PHP session variables from Javascript. However, a Javascript function can make an AJAX/XMLHttpRequest to a PHP script and that script in turn can modify the session. If the PHP script being requested by Javascript is not saving session data correctly you'll need to do some session troubleshooting in your PHP script:

  1. Are you calling session_start() or is session.auto_start enabled in php.ini?
  2. Are you using session_write_close() before redirecting away from or exiting the PHP script?
  3. Check the headers (using a tool like Firebug). Is the PHPSESSID cookie being sent by the Javascript request?
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜