Login Script
May 14, 2008
//Create Table
CREATE TABLE `login` (
`username` varchar(16) NOT NULL,
`password` varchar(100) NOT NULL,
PRIMARY KEY (`username`)
) ENGINE=MyISAM;
INSERT INTO `login` VALUES (‘alamin’, md5(‘053038′)),
INSERT INTO `login` VALUES (‘pollob’, md5(‘053031′));
//login.php
<center>
<table border=’1′>
<form method=”POST” action=”authenticate.php”>
<tr><td colspan=”2″ align=”center”>Log In</td></tr>
<tr>
<td><b>Username:</b></td>
<td><input type=”text” name=”username” size=”15″></td>
</tr>
<tr>
<td><b>Password:</b></td>
<td><input type=”password” name=”password” size=”15″></td>
</tr>
<tr>
<td colspan=”2″ align=”center”>
<input type=”submit” value=”submit” name=”submit”>
</td>
</tr>
</form>
</table>
</center>
//authenticate.php
<?php
ob_start();
mysql_connect(“localhost”, “root”) or die (“Couldn’t Connect to the server”);
mysql_select_db(“db_name”) or die (“Couldn’t Connect to database”);
// Define username and password
$username=$_POST['username'];
$password=$_POST['password'];
$crypt_pwd = md5($password);
$sql=”SELECT * FROM login WHERE username=’$username’ and password=’$crypt_pwd’”;
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
session_register(“username”);
session_register(“password”);
$_SESSION['username'] = $username;
print “<center>”;
print “<font face=’Arial’ size=’4′ color=’red’>logged in successfully.”;
print “Redirecting ….. <META HTTP-EQUIV = ‘Refresh’ Content = ‘2; URL=sucess.php’>”;
print “</font></center>”;
}
else {
print “<center>”;
print “<font face=’Arial’ size=’4′ color=’red’>Wrong username or password, redirecting back to login page…..
<META HTTP-EQUIV = ‘Refresh’ Content = ‘2; URL =login.php’></font></center>”;
}
ob_end_flush();
?>
//sucess.php
<?php
session_start();
$get = $_SESSION['username'];
print “<center>”;
print “<font face=’Arial’ size=’4′ color=’red’>Welcome $get</font>”;
print “</center>”;
?>









Trackback this post | Subscribe to the comments via RSS Feed