简体   繁体   中英

AJAX Login - Session Problem

I have created a working login script using AJAX and PHP, but my problem is - it makes me login twice before it can remember a session. Initially it uses js response to update the contents but if I refresh the page, everything turns back to its previous state. When I login for the second time and refresh the page, it's the only time it will work. Why is this happening?

You can check my files here:

  1. login.php - http://pastebin.com/8UfyfuU1

  2. users.php - http://pastebin.com/VBqMkpHH

Its because you're not logged in while you connect to login.php but after you send the request you are. I suggest a js refresh after the http request sends back that you are logged in. See if that works, for exampe, if it returns 1, that means that the login data was correct and the page will refresh and you are logged in. If it returns 0, display a message that the login data was not correct. I don't know if it works but i assume.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM