1

I've created a session variable and stored a value "123456" in it. I need that value on another page that is called using ajax. I cannot access the session variable when making the ajax call. session_start() is in top of both pages. I even tried to write the actual session value to a txt file from the page that the ajax function calls, but the file turned out blank.

What to do?

1
  • You are probably doing something wrong, an ajax call is not much different then any other http request. Sharing the code might help. Commented May 7, 2012 at 15:07

1 Answer 1

2

You cannot access PHP session info from Javascript (I'm assuming that this is what you're trying to do). You can pass it in as a hidden field or in the JS (dynamically added with PHP) to the second page, add it to a regular cookie, or provide it from PHP as a response to an AJAX request, but I think those are your only options.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok thanks... strange, everything else on the PHP page works as normal, one would think the session variable would work as well. Ok i think the best thing to do then is to pass it with the GET method.
@user1121487 is it on the same domain as the first page?

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.