Problems with PHP, MySQL based log-in system

…衆ロ難τιáo~ 提交于 2019-12-06 21:45:33

The one thing that jumps out at me is the following:

header('Location: http://example.com/members');
session_write_close();
exit();

I would place the session_write_close() call before the header('location ...')

Are any 'headers already sent' errors showing up in your logs?

Other thing that comes to mind is some AJAX race condition. Any async calls going on with login pages?

The way I do login system is to just use the session id, rather than storing anything in the session itself. When a user logs in their hashed user agent data, their session ID, their user id (corresponding to a users table) and an expiry time is put into a table, often called "active_users", I then had a logged in head file included in every admin restricted page that starts the session, retrieves the users session ID and checks to see whether that session ID is in the active users table and whether the user being checked against has the same user agent data, the expiry time is not surpassed. If nothing is returned from that query they're not logged in and are bounced out.

That's how most login systems I make work and I haven't had any problems.

Success! Still need to narrow down exactly what change resulted in the problem going away, but the client reports that he no longer has problems logging in.

The biggest change that immediately comes to mind was removing session_write_close() just about everywhere. It may have been placed AFTER the header redirect in parts of the code, or just having it present may have been the cause. I will experiment with placing it before the redirect.

Thanks to all for your suggestions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!