Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How can I assign the session value to a javascript variable. For example, I want to assign the $_SESSION['name'] to javascript variable name. Thanks.

share|improve this question
add comment

1 Answer

Well, four options:

  • Set it with php, in the javascript
    <script type="javascript">var name = "<?php echo $name; ?>";</script>
  • Set a cookie with php, and retrieve it with javascript (Javascript cookies, PHP cookies)
  • Use jquery Ajax (Visual Jquery) (Jquery Ajax)
  • Set it as a GET variable (append it to the end of the url) (Like this)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.