0

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!

1
  • 7
    Nope. PHP = server side. JS = client side... Seems like you're trying to do something difficult which could be easily done with PHP only Commented Apr 10, 2013 at 12:33

2 Answers 2

2

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

var mySessionVariable = "<?php echo $_SESSION['sessionVariable']; ?>";
Sign up to request clarification or add additional context in comments.

4 Comments

No that does not seem to work. What I am trying to do is simple have some variables be available from all around the site. I have a back button on a simple email form, which when pressed the desired result is that it would go back to the previous page with all of the data still in the form fields. I had it working using the hostiry.Back() method. But i cant use that in IE.
More comfortable for client-side coding than write to document.cookie -- Wrote this at the same time as you. You still can use this approach, just include this reusable piece of code to "master" script. Or you can use @cipher answer, but using document cookie requires some additional code.
you should look out for COOKIE then and moreover are you setting those values in session or not
@Deepanshu : This is not right way to write the code with mixing of both client and server side codes.. If I'm disable my client side script it's not working.
0

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")

1 Comment

I wish i could use cookies, but the company I am doing it for do not want me to use cookies. I guess I will have to find another way if possible.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.