Friday, October 2, 2009

login page in PHP(naive)

This example shows how to design the login page of a web site in php for naive programmers.

First create the database(I am using mysql)


CREATE TABLE login (
user_id INT AUTO_INCREMENT NOT NULL,
user_name VARCHAR(25) UNIQUE NOT NULL,
password VARCHAR(16) NOT NULL,
PRIMARY KEY(user_id)
);


Now, let's insert some data.

INSERT INTO login
(user_name, password)
VALUES
('asit', 'lipu');

INSERT INTO login
(user_name, password)
VALUES
('google', 'yahoo');


Now this is the html page that displays the login page.

login.html




Now let's make the php code that makes the necessary database connection..

database.php



$hostname = "localhost";
$username = "root";
$password = "iitiit";
$database = "db2";
$link = mysql_connect($hostname, $user, $password)or die("Mysql con't be connected");
mysql_select_db($database, $link) or die("Database can't be connected");
?>


As the user enters the username and password, the requested information is sent to the server and the login.php script will be invoked.
Here is the code

login.php




If the user successfully logs in, then the page is redirected to welcome.php, otherwise to error.html

welcome.php




error.html




Few unknown facts

  • No website in this world uses this technique as the login information is not encrypted.

No comments:

Post a Comment