Callum Holden
Callum Holden

Reputation: 51

Accessing session variables in a php file using javascript?

I want to know if there is a way to access the variables set by php using java-script, so that on one page the php variables are set. And then on the next page, i can use java-script to interrogate the PHP file in order to extract the variables, so that they can be displayed on another page?

Thanks in advance!

Upvotes: 0

Views: 995

Answers (2)

cipher
cipher

Reputation: 2484

The only way, you would do it, is by setting cookies from PHP (or Javascript), and access these.. You can access cookies via PHP using $_COOKIE['var'], and via Js by, document.cookie("var")

Upvotes: 0

Deepanshu Goyal
Deepanshu Goyal

Reputation: 2813

Not sure if this works, works for my get and post variables

var mySessionVariable = "<?php echo $_SESSION['sessionVariable']; ?>";

Upvotes: 2

Related Questions