A
A
Andrew2016-10-12 19:38:12
PHP
Andrew, 2016-10-12 19:38:12

Why is PHP session data not being read when working with AJAX?

Hi all.
The second day I struggle with the problem. The site works on local hosting, but not when transferred to an external server.
During authorization from JS, 2 AJAX requests are sequentially called:
1- Authorization and saving user data in the session.
this piece works, what is needed is saved in the session ...
2. A menu of options available to the user is formed.
But here it doesn't work. A response comes in which the parameter values ​​taken in the session are empty (user id, for example).
At the same time, the session file is alive, there is data in it. Those. in the first case, it was recorded, and in the second, the session was not considered ...
Requests go to the same php file (it is where session_start is located) and then, depending on the key, this or that file with the request and processing is included.

Who can advise what?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2016-10-12
@larush

If requests are called simultaneously, then the session file is locked by the first request and held until the end of the script or until session_write_close().

P
Philipp, 2016-10-12
@zoonman

Check that the session is issued for the entire domain (the path parameter inside the session cookie).
Check that the cookie is passed in the second Ajax request and the request goes to the same domain.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question