Get a PHP $_SESSION variable from Jquery?


I'm not yet a JSON/AJAX master so I don't know how to do this.

I need a $_SESSION['name'] PHP variable to work with in my jQuery stuff and I don't know how to access it... consider:

// the 'who is typing' shindig
        url: "whos_typing.html",
        cache: false,
        success: function(whos)
                // here I need to access $_SESSION['name'] and do stuff with it

            $("#soandso").html(whos); //Insert who's typing into the #soandso       
By : khaverim


You need to echo the session variable from PHP when you send it to the browser. I'm assuming whos_typing.html is just the URL to a PHP script.

By : Jordan

The easiest way is probably to include your javascript code in a .php file. Then you can simply do:

var phpVar = 

Server side in whos_typing.php:

This video can help you solving your question :)
By: admin