-5
我需要在我的代碼中記住我的功能。我設置了會話,但我不知道如何設置cookie以記住我。請在我的登錄頁面下方設置記住我的代碼。我嘗試了很多網站,但我沒有得到確切的輸出。記住我登錄頁面的功能
<?php
session_start();
ob_start();
error_reporting (E_ALL^E_NOTICE);
$con=mysql_connect("localhost","root","");
mysql_select_db("pratice") or die (mysql_error());
$username=$_POST['username'];
$password=$_POST['password'];
$remember=$_POST['remember'];
if(isset($_POST['submit']))
{
$sql="select id, username FROM `action2` WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if($num>0)
{
$row=mysql_fetch_array($result);
$username=$row['username'];
$_SESSION['id'] = $row['id'];
$_SESSION['username']=$username;
header("location:userpage.php");
}
else
{
echo"<p><center><b><font color='red'>Incorrect Username or Password!</font></b></center></p>";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Log In</title>
</head>
<body>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<table align="center">
<tr>
<td colspan="2">LOGIN</td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td align="right"><input name="remember" type="checkbox" value=""/></td>
<td>Remember me</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="LogIn" /></td>
</tr>
</table>
</form>
<br />
</body>
</html>
http://php.net/manual/en/function.setcookie.php - > Google上的五秒鐘。 – ATaylor 2012-08-14 05:37:57
請參考此[鏈接](http://evolt.org/node/60265/) – Vinay 2012-08-14 05:38:29
你曾嘗試過什麼?這段代碼表明你沒有嘗試過任何東西。至少要努力在谷歌上搜索。 – 2012-08-14 05:38:31