<?php
session_start();
if(isset($_SESSION["username"]) && $_SESSION["username"] != null){
header("location:index.php");
}
?>
<html>
<head>
<script type="text/javascript">
function validate(form_id,username,password) {
var reg = /^[a-zA-Z]{3,}$/;
var reg1 = /^[a-zA-Z0-9]{6,}$/;
var username = document.forms[form_id].elements[username].value;
var password = document.forms[form_id].elements[password].value;
if(reg.test(username) == false) {
alert('Invalid Username');
return false;
}
if(reg1.test(password) == false) {
alert('Invalid Password');
return false;
}
}
</script>
</head>
<body>
<form id="form_id" name="login" method="POST" action="login.php" onsubmit="javascript:return validate('form_id','username','password');">
<table border="0">
<tr>
<td>* Username :</td>
<td><input type="text" name="username" id="username"></td>
</tr>
<tr>
<td>* Password :</td>
<td><input type="password" name="password" id="password"></td>
</tr>
<tr>
<td><input type="submit" name="login" value="Login"> </td>
<td><a href="forgotpassword.php">Forgot Password</a></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['login'])){
include "config.php";
$username=$_POST['username'];
$password=$_POST['password'];
$sql="SELECT * FROM simple WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
$login=mysql_num_rows($result);
if($login)
{
$_SESSION["username"] = $username;
header("location:index.php");
}
else
{
echo "Wrong Username or Password";
}
}
?>
</body>
</html>
Post a Comment