Click here to Skip to main content
15,888,027 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a
C++
$_SESSION['nome'];
with some content, I need to assign that value to a JS variable. In "bad terms" that's it:

C++
var jogador =  <?php'$_SESSION['nome']; ?>;


Of course this not work because the client-server-side situation, so I'm wondering, how can I solve my problem? I really cant do the opposite (use JS inside PHP) so I appreciate any help.

I'm thinking writing that session on a hidden text field then use JS to get the value from that text box, but not an elegant solution at all.

Regards.
Posted
Updated 13-Mar-11 17:22pm
v3

1 solution

Instead of storing the variable in session use encrypted cookies. The cookies can be readable at client side.
 
Share this answer
 
Comments
Maxdd 7 14-Mar-11 0:19am    
That was my "second alternative". I just becoming curious about another way, you guys always remember a tricky solution :)
Albin Abel 14-Mar-11 0:24am    
Thanks Maxdd. If you don't think ajax is tricky then you can have server side code which read that session variable, then that code can be accessed through ajax from javascript. Is it ok for an alternative?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900