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 page contents (as logged user) but if I refresh the page, everything turns back to its previous state (login form appears again). When I log-in for the second time and refresh the page, it's the only time it will work. Does anybody know why is this happening?
You can check my files here:
1. login.php -
http://pastebin.com/8UfyfuU1
2. users.php -
http://pastebin.com/VBqMkpHH
---UPDATE---
Fixed. (My stupid mistake)