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

From: Date: Mon, 08 Aug 2005 17:09:26 +0000
Subject: Re: Can I retrieve a stored php session variable from within a javascript function?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-220233@lists.php.net to get a copy of this message
Thanks Rick, it helped. also I'll do some reading about AJAX (as soon as I can..) Regards Mauricio On Sat, 2005-08-06 at 11:58, Rick Emery wrote: > 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 (#220233) next »