|
|
| LOG IN WITH PHP |
|
It is often use for a login system to avoid some users. For example
in forums or a protected system. In this tutorial I will show you how to
log in to a site and check if the user exists in the database whith correct password.
|
The User table
|
|
I call the table that contains the users for myUsers. This has two colums:
Name and Password.
|
display.php
|
|
I made two texfields; one where you can write your username, and one where you can write
the password. I wrap this into a form and add a submit button. Something like this:
|
|
|
login.php
|
|
In order to let the user log in, you have check if the user exists.
I am setting the variables passed from display.php into varibles and
check them, using a sql statement, if the user exists.
The sql statement I use checks if there are any records which satisfy
this statement. If so a user with this password exists and I make a cookie
for him:
|
|
|
secret.php
|
|
I have made a secret file that just registered users are allowed to view.
At the topp of the file I make a test to see if the user have assigned a
cookie, if so he get to se the secret message :) Like the code below.
|
|
|
|
Category
|
Programming with PHP
|
|
Author
|
Tommy Johannessen
|
|
|
|