| | |
login script using sessions
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
That's a lot of questions in one. It would be nice to know what you already know. To develop a login script using sessions stored in a database, you'll need to know how to:
The basics of how I do it is I create a script named login.php for example. This script will serve these functions:
The other part of the equation is to build an include script that you include in every PHP page you want to protect. This script checks the session to see if the user is authenticated. (Do this by checking whatever session variable you use to test or by looking at whatever POST or GET parameter you use to maintain the session.) If the user is not logged in, redirect to login.php. Otherwise allow the page to proceed. (When you redirect to login.php, pass the current filename to login.php to "remember" the requested page so that once authentication passes, you can redirect back to where the user was going.
I hope this helps you understand the architecture of building such a system. If you are not a PHP programmer already, then you really need to start with learning PHP. This would not be a good PHP tutorial project in my opinion.
- Program with PHP
- Connect to a database to insert, update, and select data using PHP.
- Redirect to another page in PHP
- Use PHP includes
- Build an HTML form
- Process an HTTP POST or GET in PHP.
The basics of how I do it is I create a script named login.php for example. This script will serve these functions:
- Output an HTML login form.
- As the target of the form, process the form to test the username and password against your authentication source--most likely a database.
- If authentication fails, re-output the login form with a failure message so the user can try again.
- If authentication succeeds, create a session and/or save session data in database, then redirect to the originally requested page.
The other part of the equation is to build an include script that you include in every PHP page you want to protect. This script checks the session to see if the user is authenticated. (Do this by checking whatever session variable you use to test or by looking at whatever POST or GET parameter you use to maintain the session.) If the user is not logged in, redirect to login.php. Otherwise allow the page to proceed. (When you redirect to login.php, pass the current filename to login.php to "remember" the requested page so that once authentication passes, you can redirect back to where the user was going.
I hope this helps you understand the architecture of building such a system. If you are not a PHP programmer already, then you really need to start with learning PHP. This would not be a good PHP tutorial project in my opinion.
![]() |
Similar Threads
- Logon Script - Default, forced, compulsory,etc.etc. (Windows NT / 2000 / XP)
- Trying to create a login system (PHP)
- how to make member expire after so many days with php script (PHP)
- php help needed for login (PHP)
Other Threads in the PHP Forum
- Previous Thread: adding a database to my webpage
- Next Thread: look-up table help
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube





