0

Can I from Dojo or plain JavaScript anyhow to 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 ?

1
  • 2
    you can echo it out to javascript or html like var myvar = "<?php echo $_SESSION['myvar']; ?>";
    – KJYe.Name
    Mar 21, 2011 at 15:04

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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