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:
- Are you calling
session_start()
or issession.auto_start
enabled in php.ini? - Are you using
session_write_close()
before redirecting away from or exiting the PHP script? - Check the headers (using a tool like Firebug). Is the PHPSESSID cookie being sent by the Javascript request?
精彩评论