Answer the question
In order to leave comments, you need to log in
Why if the script does not work, then when executed in xdebug everything works fine?
I've already broken my head. There is a strange thing. There is a site script (I wrote everything myself without frameworks), the logic is something like this, when you enter the page, an authorization check is performed (whether there are cookies or a session), if the user is authorized, then an object of this user is created in the base controller.
On some pages, it checks whether it is authorized and, depending on the result, redirects to one or another page.
We take an example from a common problem:
1) I go to the authorization page
2) I fill out the form and send it
3) I set cookies and the session_id is written to the session
4) immediately after authorization, a redirect to the user account page occurs
5) there is a check in the controller whether there is any user or he is null
6) if null, then redirect to the authorization page and show an error, otherwise show the page with user data.
In fact, I have a glitch at points 4 and 5, that is, immediately after the redirect to the account page, it is shown that $user = null, and only after the page is refreshed does $user appear. I have the same problem when I enter the authorization page, if I am logged in, the controller sees that I am logged in and directs me to the account page, but the account controller does not see it and sends me back to the login page with an error.
Everything would be fine, I decided to run it through xdebug, see where the error was, and he showed me a fig and the whole script went perfectly, that is, everything worked out as it should ...
I apologize for the confusion of the question, in truth I don’t really understand how to ask in just such a situation. I don’t see the point in giving the code as an example, there is already a lot of it, but in order to show one part, I don’t know which one. But there is a problem, I can’t even imagine why and how this can happen and why it works with the debugger. Maybe someone has ideas?
Answer the question
In order to leave comments, you need to log in
I found what the problem is. If suddenly someone will have something similar, then the following happened to me:
Every time I load a page, the script checks whether I am logged in or not, by cookie and session. The code is strongly tied to the fact that it looks at my session and makes a request to the database to update the time of my last visit in the sessions table, if after the request zero affected rows are returned, then the session in the script is reset to zero.
It turned out that after authorization, when there is a redirect to another page (and this is already two page requests), the second request occurs within the same second as the first one, therefore the last activity time is not updated and the script sends me. But with the debugger, everything happens with a delay, so there was no such problem there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question