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:

  1. Start a session : Session_start ()
  2. Session ["user"] == Zero, redirect to login page, and continue.
  3. In the login page,
  4. Post this form on the login page
  5. Check against your authorization service (like the table in my SQL) if the user is authorized
  6. 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

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -