authentication - PHP, Prevent users from accessing a page while not logged in? -
How can I stop the user from accessing a page when I'm not logged in? I want him to be redirected to the login page. I know that there is something to do in the session.
This works like this:
- Start a session : Session_start ()
- Session ["user"] == Zero, redirect to login page, and continue.
- In the login page,
- Post this form on the login page
- Check against your authorization service (like the table in my SQL) if the user is authorized
- If so, the session ["user"] = $ username, redirect the user to the page. If not, then prompt for the password
Of course, all this is very simple, in your session, you can keep a complex user object, or anything. Best wishes coding
Comments
Post a Comment