在PHP中,编写一个登录程序,假定用户为“www”,密码为“123”在用户输入如果用户名和密码正确,则提示欢迎回来,然后将用户的密码信息分别以cookie和session的形式保存在浏览器端和服务器端上
第1个回答 2011-10-31
<?
if($_POST['submit']){
if($_POST['username']=='www'&&$_POST['passwd']=='123'){
setcookie("cookie", "ok");
echo "<script type=\"text/javascript\" >alert(\"欢迎回来\")</script>";
}
}
?>
<form action ="<?=$_SERVER['PHP_SELF']?>" name="form1" method="post" >
用户名:<input type="text" name="username" /><br>
密码:<input type="password" name="passwd" />
<input type="submit" name="submit" value="登陆"/>
</form>本回答被网友采纳
if($_POST['submit']){
if($_POST['username']=='www'&&$_POST['passwd']=='123'){
setcookie("cookie", "ok");
echo "<script type=\"text/javascript\" >alert(\"欢迎回来\")</script>";
}
}
?>
<form action ="<?=$_SERVER['PHP_SELF']?>" name="form1" method="post" >
用户名:<input type="text" name="username" /><br>
密码:<input type="password" name="passwd" />
<input type="submit" name="submit" value="登陆"/>
</form>本回答被网友采纳
第2个回答 2011-10-31
这个需要读数据库的吧~ 根据你得到的 用户名和密码,读取数据库,数据库中存在,再设置cookie 和 session 的吧!
第3个回答 2011-10-31
<?
if($_POST){
if($_POST['username']=='www'&&$_POST['passwd']=='123'){
setcookie("cookie", "ok");
echo "<script type=\"text/javascript\" >alert(\"欢迎回来\")</script>";
}
}
?>
<form action ="<?=$_SERVER['PHP_SELF']?>" name="form1" method="post" >
用户名:<input type="text" name="username" /><br>
密码:<input type="password" name="psd" />
<input type="submit" name="submit" value="登陆"/>
</form>
if($_POST){
if($_POST['username']=='www'&&$_POST['passwd']=='123'){
setcookie("cookie", "ok");
echo "<script type=\"text/javascript\" >alert(\"欢迎回来\")</script>";
}
}
?>
<form action ="<?=$_SERVER['PHP_SELF']?>" name="form1" method="post" >
用户名:<input type="text" name="username" /><br>
密码:<input type="password" name="psd" />
<input type="submit" name="submit" value="登陆"/>
</form>