html下拉列表方式的用户名,如何实现记住用户名和密码功能??后台是php,请大仙们指教 10
1个回答
展开全部
用COOKIE. 看看下面的对你有帮助没
remember.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form id="form1" name="form1" method="post" action="check_remember.php">
<table width="300" border="1" align="center" cellpadding="0" cellspacing="0">
<thead>
<tr>
<td colspan="2" align="center"><b>记住用户名和密码</b></td>
</tr>
</thead>
<tr align="center">
<td>用 户 名:</td>
<td><input type="text" value="<?php echo $_COOKIE['name'];?>" name="name"></td>
</tr>
<tr align="center">
<td>密码:</td>
<td><input type="password" name="password" value="<?php echo $_COOKIE['password']?>"></td>
</tr>
<tr align="center">
<td>记住用户名和密码</td>
<td><?php if($_COOKIE['remember'] == 1){?><input type="checkbox" name="remember" value="1" checked><?php }else{($_COOKIE['remember'] == "")?><input type="checkbox" name="remember" value="1"><?php }?></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="Submit" value="提交" /></td>
</tr>
</table>
</form>
check_remember.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
$name = $_POST['name'];
$password = $_POST['password'];
$remember = $_POST['remember'];
if($remember == 1){
setcookie('name',$name,time()+3600);
setcookie('password',$password,time()+3600);
setcookie('remember',$remember,time()+3600);
}else{
setcookie('name',$name,time()-3600);
setcookie('password',$password,time()-3600);
setcookie('remember',$remember,time()-3600);
}
echo "<a href=\"remember.php\">返回</a>";
?>
remember.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form id="form1" name="form1" method="post" action="check_remember.php">
<table width="300" border="1" align="center" cellpadding="0" cellspacing="0">
<thead>
<tr>
<td colspan="2" align="center"><b>记住用户名和密码</b></td>
</tr>
</thead>
<tr align="center">
<td>用 户 名:</td>
<td><input type="text" value="<?php echo $_COOKIE['name'];?>" name="name"></td>
</tr>
<tr align="center">
<td>密码:</td>
<td><input type="password" name="password" value="<?php echo $_COOKIE['password']?>"></td>
</tr>
<tr align="center">
<td>记住用户名和密码</td>
<td><?php if($_COOKIE['remember'] == 1){?><input type="checkbox" name="remember" value="1" checked><?php }else{($_COOKIE['remember'] == "")?><input type="checkbox" name="remember" value="1"><?php }?></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="Submit" value="提交" /></td>
</tr>
</table>
</form>
check_remember.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
$name = $_POST['name'];
$password = $_POST['password'];
$remember = $_POST['remember'];
if($remember == 1){
setcookie('name',$name,time()+3600);
setcookie('password',$password,time()+3600);
setcookie('remember',$remember,time()+3600);
}else{
setcookie('name',$name,time()-3600);
setcookie('password',$password,time()-3600);
setcookie('remember',$remember,time()-3600);
}
echo "<a href=\"remember.php\">返回</a>";
?>
追问
用户名input框type为text的我会,
用 户 名:
用户名为下拉框的,而且下拉框的数据还要从数据库获取,如果单纯将$_COOKIE['name']放在select标签里,无疑会挤占下拉框option的值,用select形式选择用户名登陆,如何记住用户名和密码呢?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询