Re: Can I retrieve a stored php session variable from within a javascript function?

From: Date: Sat, 06 Aug 2005 14:58:22 +0000
Subject: Re: Can I retrieve a stored php session variable from within a javascript function?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-220142@lists.php.net to get a copy of this message
Quoting Mauricio Pellegrini <hrrg-inf@speedy.com.ar>:
Hi , I wonder if it's possible to retrieve the value from a php session variable from within a javascript function.
I'm no PHP expert, but I'll give it a try (there are plenty of smart people on this list who will correct me if Im wrong :-)
Does anyone have any ideas about this?
Yes, two of the top of my head. 1. You can send the session variable to the client along with the script. ex. function doSomething() { sessVar = <?php print($_SESSION['variable']); ?>; // Do some stuff. } Of course, sessVar won't be updated if the session variable changes unless the script is reloaded. 2. My favorite, but probably overkill. Write a php page that outputs the session variables (as XML would be cool). Then use xmlhttprequest to retrieve them from javascript (Google AJAX for more information). Hope this helps, Rick -- Rick Emery "When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for there you have been, and there you will always long to return" -- Leonardo Da Vinci

« previous php.general (#220142) next »