SQL
CREATE TABLE IF NOT EXISTS `members` (
`member_id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(100) NOT NULL,
`password` varchar(100) NOT NULL,
`firstname` varchar(100) NOT NULL,
`lastname` varchar(20) NOT NULL,
`status` int(1) NOT NULL,
PRIMARY KEY (`member_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
--
-- Dumping data for table `members`
--
INSERT INTO `members` (`member_id`, `username`, `password`, `firstname`, `lastname`, `status`) VALUES
(1, 'admin', 'admin', 'System', 'admin ', 1),
(2, 'les', 'les', 'Leslie Vinky', 'Pepito', 1),
(3, 'al', 'al', 'Albert', 'Pepito', 0),
(4, 'yana', 'yana', 'Gelia', 'Pepito', 1),
(5, 'allie', 'allie', 'Ma. Junallie', 'Pomperada', 1),
(7, 'ali', 'ali', 'Ali', 'Amar', 0);
////////////////////////////
<!-- login.php -->
<!-- Created By: Mr. Aamir Javed Awan -->
<!-- Tools : PHP/MySQL -->
<html>
<head>
<title>Login Security 1.0</title>
<script type="text/javascript">
function setFocus()
{
document.getElementById("user").focus();
}
function focusReset(){
document.login.user.value="";
document.login.pass.value="";
document.login.user.focus();
}
function Blank_Validator()
{
if (document.login.user.value == "" )
{
alert("Please fill the user name.");
document.login.user.focus();
return (false);
}
else if (document.login.pass.value == "" ){
alert("Please fill the password.");
document.login.user.focus();
return (false);
}
return (true);
}
</script>
</head>
<style>
input[type='text'] { font-size: 20px; color: blue; }
input[type='password'] { font-size: 20px; color: blue;}
.uni, .uni td,.uni th, .uni tr
{
font-family:comic sans ms;
font-size:15pt;
color: blue;
}
</style>
<?php
include 'connect.php';
if (isset($_REQUEST['ok']))
{
// Grab User submitted information
$user = $_REQUEST["user"];
$pass = $_REQUEST["pass"];
$result=mysql_query("select * from members where username='$user'
AND password='$pass'")or die (mysql_error());
$count=mysql_num_rows($result);
$row=mysql_fetch_array($result);
$result2 =mysql_query("select * from members where username='$user'
AND password='$pass' and status = 0")or die (mysql_error());
$count2=mysql_num_rows($result2);
$row2=mysql_fetch_array($result2);
$faculty_query =mysql_query("select * from members where username='$user'
AND password='$pass' and status = 2")or die (mysql_error());
$count3=mysql_num_rows($faculty_query);
$row3=mysql_fetch_array($faculty_query);
if ($count > 0 )
{
session_start();
$_SESSION['member_id']=$row['member_id'];
$message = "<script language=javascript> location.href='welcome.php' </script>";
}
else
{
$message= "<script language=javascript>
alert(\"Sorry Invalid Password And User Name. Register Please\");</script>";
}
if ($count2 == true)
{
$message = "<script language=javascript> location.href='hello.php' </script>";
//$message= "<script language=javascript>
// alert(\"This account is deactivated. Please contact us for account activation.\");</script>";
}
if ($count3 == true)
{
$message = "<script language=javascript> location.href='faculty.php' </script>";
}
mysql_close($con);
}
?>
<br><br>
<font size=12 face="comic sans ms" color="blue"> <center>
Login Security </font> </center>
<br>
<body bgcolor="lightgreen" onload="setFocus()">
<center>
<form name="login" method="post" action=""
onsubmit="return Blank_Validator()" >
<table border class="uni">
<tr>
<td><label for="users">Username</label></td>
<td><input type="text" name="user" id="user"></td>
</tr>
<tr>
<td><label for="pass">Password</label></td>
<td><input type="password" name="pass" id="pass"></input></td>
</tr>
<tr>
<td><input type="submit" name="ok" value=" OK "
title="Click here to login in the system"/>
<td>
<input type="button" value=" CLEAR " onClick='focusReset()'
title="Click here to clear the text box"/>
</tr>
</table>
</form>
<font face="comic sans ms">
<center><h3><a href='registerform.php' title='Click here to Register New Use Account.'>Registration</a></h3></center> </font>
</center>
<?php echo $message ?>
</body>
</html>
<?php
//connect.php -->
error_reporting(0);
// Connect to the database
$con = mysql_connect("localhost","root","");
// Make sure we connected succesfully
if(!$con)
{
die('Connection Failed'.mysql_error());
}
// Select the database to use
mysql_select_db("user_pass",$con);
?>
<?php
// config_all.php
// creation of database,table and insert of sample records.
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE user_pass",$con))
{
echo "<br><br>";
echo "<h3>Your database has been created !!! <h3>";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_select_db ("user_pass", $con);
$query1 = 'CREATE TABLE members( '.
'member_id INT(11) NOT NULL AUTO_INCREMENT, '.
'username VARCHAR(100) NOT NULL, '.
'password VARCHAR(100) NOT NULL, '.
'firstname VARCHAR(100) NOT NULL, '.
'lastname VARCHAR(20) NOT NULL, '.
'status INT(1) NOT NULL, '.
'PRIMARY KEY(member_id))';
if (mysql_query($query1,$con))
{
echo "<h3> Your table has also created !!! </h3>";
}
else
{
echo "<br>";
echo "Error creating table: " . mysql_error();
}
mysql_query("INSERT INTO members
(member_id,username, password,firstname,lastname,status)
VALUES ('1', '123','123','Jake', 'Pomperada ',0),
('2', 'les', 'les', 'Leslie Vinky', 'Pepito',1),
('3', 'al', 'al', 'Albert', 'Pepito',0),
('4', 'yana', 'yana', 'Gelia', 'Pepito',1),
('5', 'allie', 'allie','Ma. Junallie', 'Pomperada',1)
") or die(mysql_error());
echo "<h3> Record has been inserted in table. </h3>";
mysql_close($con);
?>
//register.php
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Registration Form</title>
</head>
<body bgcolor="lightgreen" style="color:blue;">
<?php
$servername="localhost";
$username="root";
$conn= mysql_connect($servername,$username)or die(mysql_error());
mysql_select_db("user_pass",$conn);
if ( !$conn )
{
die( 'Could not connect: ' . mysql_error() );
}
$username = $_GET['regusername'];
$password = $_GET['regpassword'];
$firstname = ucfirst($_REQUEST['regfirstname']);
$lastname = ucfirst($_REQUEST['reglastname']);
$status = $_REQUEST['status'];
if (mysql_num_rows(mysql_query("SELECT *
FROM members WHERE username = '$username' AND
password = '$password'"))) {
$message= "<script language=javascript>
alert(\"Username and Password Already Exist.\");</script>";
echo $message;
$message2 = "<script language=javascript> location.href='registerform.php' </script>";
echo $message2;
}
else
{
$sql = mysql_query("INSERT INTO members (username, password, firstname, lastname,status)
VALUES ('$username', '$password', '$firstname','$lastname','$status')");
$result=mysql_query($sql,$conn);
mysql_close($conn);
}
print "<h1>Congratulation you have registered sucessfully</h1>";
print "<a href='index.php'>go to login page</a>";
?>
</body>
//registerform.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Registration Form</title>
</head>
<body bgcolor="lightgreen" style="color:blue;">
<FORM ACTION="register.php" METHOD=get>
<font face="Comic Sans Ms">
<h1>Welcome To Registration Form</h1>
Please input the registration details to create an account here<br> <br>
<table border="2">
<tr>
<td>User Name :</td><td><input name="regusername" type="text" size"20"></input></td>
</tr>
<tr>
<td>Password :</td><td><input name="regpassword" type="password" size"20"></input></td>
</tr>
<tr>
<td>First Name :</td><td><input name="regfirstname" type="text" size"20"></input></td>
</tr>
<tr>
<td>Last Name :</td><td><input name="reglastname" type="text" size"20"></input></td>
</tr>
<td>Status : 1 - Active 0 - Non Active</td><td><input name="status" type="text" size"1"></input></td>
</tr>
</table> </form> <br>
<input type="submit" value="Register me!"></input>
</FORM>
</body>
</html>
hello.php
<html>
<body bgcolor="Blue">
<h1 align="center">
Your are deactivated in your account please contact us asap !!!!
</h1>
</body>
</html>
Faculty.php
<html>
<body bgcolor="yellow">
<h1 align="center">
Welcome to Faculty Page!!!!
</h1>
</body>
</html>
<?php
include 'connect.php';
session_start();
if (!isset($_SESSION['member_id'])){
header('location:index.php');
}
?>
<html>
<body bgcolor="lightgreen">
<hr noshade size="10" color="red">
<center> <h2>
<font color="blue" face="Comic Sans MS">
Welcome to the Main Page
</center> </h2> </font>
<hr noshade size="10" color="red">
<br><br>
<center>
<?php
$member_id=$_SESSION['member_id'];
$result=mysql_query("SELECT * FROM members WHERE member_id='$member_id'")
or die(mysql_error());
$row=mysql_fetch_array($result);
$FirstName=$row['firstname'];
$LastName= $row['lastname'];
?>
welcome.php
<?php
echo "<br>";
echo "<font size=6 name='comic sans ms' color='blue'>";
echo "Hello " .$FirstName." ".$LastName;
echo "</font>";
?>
<br><br><br>
<font size=5 name="comic sans ms" >
<a href="logout.php" title="click here to logout.">
Logout</a>
</font> </center>
</body>
</html>
logout.php
<?php
// logout.php
session_start();
session_destroy();
header('location:index.php');
?>