开发者

Read value stored in session

开发者 https://www.devze.com 2023-02-17 23:34 出处:网络
Can I from Dojo or plain JavaScript anyhow to 开发者_JS百科read some value stored in session ? I stored in php in session if user is logged or not but I need to read this on my page with Dojo . Can I

Can I from Dojo or plain JavaScript anyhow to 开发者_JS百科read some value stored in session ? I stored in php in session if user is logged or not but I need to read this on my page with Dojo . Can I do that and how ?


The session information is stored on the server. One way you can retrieve it using Dojo would be to create a PHP page that returns that variable to you and make an AJAX call from Dojo.

dojo.xhrGet({
    url:"getFromSession.php?var=variableToGet",
    load: function(response) {
        alert("got: " + response.responseText);
    }
})

And then your PHP file would look something like this:

<?php
    echo $_SESSION[$_GET['var']];
?>

Note that this will allow you to get any variable from the session. You may want to have your PHP page only return the value of a specific variable.

0

精彩评论

暂无评论...
验证码 换一张
取 消