<?php
if ($_POST['txtUsername'] != "" && $_POST['txtPassword'] !="")
{
$user1 = $_POST['txtUsername'];
$pass1 = $_POST['txtPassword'];
setcookie("user", "$user1");
setcookie("pass", "$pass1");
header("location:ceklogin.php");
}
//print_r($_COOKIE);
?>
<html>
<head>
<title>password protection test</title>
</head>
<body>
<p>
<b>Login</b>
</p>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div align="center">
<center>
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<td><label for="txtUsername">Username</label>
</td>
<td><input type="text" title="Enter your Username" name="txtUsername" /></td>
</tr>
<tr>
<td><label for="txtpassword">Password</label>
</td>
<td><input type="password" title="Enter your password" name="txtPassword" /></td>
</tr>
</table>
</center>
</div>
<p align="center"><input type="submit" name="Submit" value="Login" /></p>
</form>
</body>
</html>
berikut ini ceklogin.php buatan saya ..
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("tes", $con);
$result = mysql_query("SELECT * FROM member");
$result = mysql_query("SELECT * FROM member ORDER BY username");
while($row = mysql_fetch_array($result))
{
if ($_COOKIE["user"] == $row['username'] && $_COOKIE["pass"] == $row['password']) {
$cek = 1;
header("location:upload.php");
}
}
if ($cek != 1){
header("location:index.php");
}
?>
Tidak ada komentar:
Posting Komentar