2

While using the sessions in my PHP script I wanted to pass the session variable to the PHP called script. But the session variables are not being called as the session_start() function could not be used after the HTML code. I am using the simple Javascript AJAX. Please provide me the path.

4
  • I don't understand. Where is your script failing? What do you currently have? Commented Apr 12, 2012 at 13:30
  • 1
    so you can't access sessions-vars in the phpscript you call with your ajax? Commented Apr 12, 2012 at 13:31
  • you may echo your php session variable inside JavaScript Commented Apr 12, 2012 at 15:07
  • @Mohammer yeah but i found the alternative by passing session id and storing the needful details in database and on session_destroy removing the entry. Commented Apr 13, 2012 at 13:27

1 Answer 1

6

I think what you need is the following:

in your php-script you open/request with ajax, you have to add in the first line:

session_start(session_id());

This way, you have access to the variables you stored in your session where you called the request with ajax

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

1 Comment

Thanx I just passed this session id with the link passed by AJAX.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.