Skip to content

Instantly share code, notes, and snippets.

@jvadillo
Created November 10, 2017 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvadillo/f634f751d506e8c11d1ccbbea5a54495 to your computer and use it in GitHub Desktop.
Save jvadillo/f634f751d506e8c11d1ccbbea5a54495 to your computer and use it in GitHub Desktop.
Access to PHP SESSION datda from JavaScript
You can produce the javascript file via PHP. Nothing says a javascript file must have a .js extention. For example in your HTML:
<script src='javascript.php'></script>
Then your script file:
<?php header("Content-type: application/javascript"); ?>
$(function() {
$( "#progressbar" ).progressbar({
value: <?php echo $_SESSION['value'] ?>
});
// ... more javascript ...
If this particular method isn't an option, you could put an AJAX request in your javascript file, and have the data returned as JSON from the server side script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment