Yen sira kasinungan ngelmu kang marakake akeh wong seneng, aja sira malah rumangsa pinter, jalaran menawa Gusti mundhut bali ngelmu kang marakake sira kaloka iku, sira uga banjur kaya wong sejene, malah bisa aji godhong jati aking.(Bila anda mendapat anugrah ilmu yang membuat banyak orang senang, janganlah kamu merasa pintar, sebab apabila Tuhan mengambil lagi ilmu yang menyebabkan anda terkenal itu, anda akan menjadi orang biasa lagi, malah lebih bermanfaat daun yang kering)
Wednesday, May 12, 2010
login php dengan cokie
<?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");
}
?>
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.