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>”;
?>

Entry Filed under: MySQL, PHP. .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


My Fav




My twiTTer

Error: Please make sure the Twitter account is public.

Top Clicks

 

May 2008
M T W T F S S
    Jul »
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives

Category Cloud

JAVA Java Script MySQL Networking(CISCO) PHP Template Uncategorized

Recent Comments

pollobcse05 on About
মাহমুদ ফয়সাল on About
pollobcse05 on Connecting MySql With Jav…
Shamim Ahmed on Connecting MySql With Jav…
Arafat Rahman on My First WordPress Templa…

Blogroll

Meta

My Flickr Photos

SDC12881

SDC12818

SDC12808

SDC12802

SDC12794

More Photos

Pages

Blogroll

Meta