前两天我写了一个很简单的登陆页面,但是在我这编译没通过。核对了一下源码,没有错误。但就是运行不出现结果,也不报错。google 百度 也不知道需要查什么原因。找了几个phper修改了一些也不行。所以实在是没有办法,只能贴到这。希望各位抽出时间来关注一下,围观一下。不胜感激!<?php
if($_GET['out']){
setcookie("cookie", "out");
echo '<script language="javascript">location.href=\'login.php?\'+Math.random();</script>';
}
if($_POST['user'] == 'admin') {
$pw = md5($_POST['pwd']);
if($pw == 'e1bfd762321e409cee4ac0b6e841963c') {
setcookie("cookie", "ok");
echo '<script language="javascript">location.href=\'login.php?\'+Math.random();</script>';
}
}else{
echo "出错了";
}
if($_COOKIE['cookie'] != 'ok'){
?>
<!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=utf-8" />
<title>login</title>
<style type="text/css">
*{ margin:0; padding:0;}
body{ background:#FFCC66; font:12px Arial, Helvetica, sans-serif;}
ul{ list-style:none;}
#my{ width:500px; margin:20px auto;}
#my li{ height:30px;}
</style>
<script type="text/javascript" language="javascript">
<!--
function check(){
if(login.user.value==""){
alert("用户名不能为空");
login.user.focus();
return false;
}
if(login.pwd.value==""){
alert("密码不能为空");
login.pwd.focus();
return false;
}
}
-->
</script>
</head><body><form name="login" action="" method="post" onsubmit="return check();">
<ul id="my">
<li>用户:<input type="text" name="user" size="10" /></li>
<li>密码:<input type="password" name="pwd" size="10" /></li>
<li><input type="submit" name="submit" value="登陆" /></li>
</ul>
</form>
<?php
}else{
?>
<a href='?out=login'>退出</a>
<?php
}
?>
</body>
</html>
if($_GET['out']){
setcookie("cookie", "out");
echo '<script language="javascript">location.href=\'login.php?\'+Math.random();</script>';
}
if($_POST['user'] == 'admin') {
$pw = md5($_POST['pwd']);
if($pw == 'e1bfd762321e409cee4ac0b6e841963c') {
setcookie("cookie", "ok");
echo '<script language="javascript">location.href=\'login.php?\'+Math.random();</script>';
}
}else{
echo "出错了";
}
if($_COOKIE['cookie'] != 'ok'){
?>
<!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=utf-8" />
<title>login</title>
<style type="text/css">
*{ margin:0; padding:0;}
body{ background:#FFCC66; font:12px Arial, Helvetica, sans-serif;}
ul{ list-style:none;}
#my{ width:500px; margin:20px auto;}
#my li{ height:30px;}
</style>
<script type="text/javascript" language="javascript">
<!--
function check(){
if(login.user.value==""){
alert("用户名不能为空");
login.user.focus();
return false;
}
if(login.pwd.value==""){
alert("密码不能为空");
login.pwd.focus();
return false;
}
}
-->
</script>
</head><body><form name="login" action="" method="post" onsubmit="return check();">
<ul id="my">
<li>用户:<input type="text" name="user" size="10" /></li>
<li>密码:<input type="password" name="pwd" size="10" /></li>
<li><input type="submit" name="submit" value="登陆" /></li>
</ul>
</form>
<?php
}else{
?>
<a href='?out=login'>退出</a>
<?php
}
?>
</body>
</html>
哦 还是高手来指点吧
加上 login.submit();
<?php
if($_GET['out']){
setcookie("cookie", "out");
echo '<script language="javascript">location.href=\'login.php?\'+Math.random();</script>';} if($_POST['submit']){
if($_POST['user'] == 'admin') {
$pw = md5($_POST['pwd']);
if($pw == '21232f297a57a5a743894a0e4a801fc3') {
setcookie("cookie", "ok");
echo '<script language="javascript">location.href=\'login.php?\'+Math.random();</script>'; }
}else{
echo "出错了";
}
}if($_COOKIE['cookie'] != 'ok'){
?>
<!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=gb2312" />
<title>login</title>
<style type="text/css">
*{ margin:0; padding:0;}
body{ background:#FFCC66; font:12px Arial, Helvetica, sans-serif;}
ul{ list-style:none;}
#my{ width:500px; margin:20px auto;}
#my li{ height:30px;}
</style>
<script type="text/javascript" language="javascript">
<!--
function check(){
if(login.user.value==""){
alert("用户名不能为空");
login.user.focus();
return false;
} if(login.pwd.value==""){
alert("密码不能为空");
login.pwd.focus();
return false;
}}
-->
</script>
</head><body><form name="login" action="" method="post" onsubmit="return check();">
<ul id="my">
<li>用户:<input type="text" name="user" size="10" /></li>
<li>密码:<input type="password" name="pwd" size="10" /></li>
<li><input type="submit" name="submit" value="登陆" /></li>
</ul>
</form>
<?php
}else{
?>
<a href='?out=login'>退出</a>
<?php
}
?>
</body>
</html>
稍微加了点东西 修改了一下 确实是MD5的问题 首先要确定MD5的值 是不是等于 你输入的值的MD5 对应么 。 还有就是 网站浏览的时候 本身没有COOKIE 所以那个出错会一直显示 给一个判断 提交之后显示 比较好。
user : admin
pwd :123456
我的环境是xampp。 php版本是5.3.1。js只是做了一个简单的判断。
谢谢dingwww421317017
回去试试 谢谢各位
var_dump($_COOKIE);//跟踪COOKIE
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>login</title>
<style type="text/css">
*{ margin:0; padding:0;}
body{ background:#FFCC66; font:12px Arial, Helvetica, sans-serif;}
ul{ list-style:none;}
#my{ width:500px; margin:20px auto;}
#my li{ height:30px;}
</style>
<script type="text/javascript" language="javascript">
function check(){
if(login.user.value==""){
alert("用户名不能为空");
login.user.focus();
return false;
} if(login.pwd.value==""){
alert("密码不能为空");
login.pwd.focus();
return false;
}}</script>
</head><body>
<div id="step1">
<form name="login" action="" method="post" onsubmit="return check();">
<ul id="my">
<li>用户:<input type="text" name="user" size="10" /></li>
<li>密码:<input type="password" name="pwd" size="10" /></li>
<li><input type="submit" name="submit" value="登陆" /></li>
</ul>
</form>
</div>
<div id="out" style="display:none"><a href='denglu.php?out=login'>退出</a></div>
<?php
if($_GET['out']){
echo '<script>document.getElementById("step1").style.display ="";</script>';
echo '<script>document.getElementById("out").style.display ="none";</script>';
}; if($_POST['submit']){
if($_POST['user'] == 'admin') {
$pw = md5($_POST['pwd']);
echo "<script>alert('".$pw."');</script>";
if($pw ==$pw) {
echo '<script>document.getElementById("step1").style.display ="none";</script>';
echo '<script>document.getElementById("out").style.display ="";</script>';
}else{echo "<script>alert('密码出错了!');</script>";};
}else{
echo "<script>alert('出错了!');</script>";
} } ;?>
</body>
</html>
if($_GET['out']){
setcookie("cookie", "out");
echo '<script language="javascript">location.href=\'login.php?\'+Math.random();</script>';
}
if($_GET['in']){
if($_POST['user'] == 'admin') {
$pw = md5($_POST['pwd']);
if($pw == 'e1bfd762321e409cee4ac0b6e841963c') {
setcookie("cookie", "ok");
echo '<script language="javascript">location.href=\'login.php?\'+Math.random();</script>';
}
}else{
echo "出错了";
} }if($_COOKIE['cookie'] != 'ok'){
?>
<!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=utf-8" />
<title>login</title>
<style type="text/css">
*{ margin:0; padding:0;}
body{ background:#FFCC66; font:12px Arial, Helvetica, sans-serif;}
ul{ list-style:none;}
#my{ width:500px; margin:20px auto;}
#my li{ height:30px;}
</style>
<script type="text/javascript" language="javascript">
<!--
function check(){
if(login.user.value==""){
alert("用户名不能为空");
login.user.focus();
return false;
}
if(login.pwd.value==""){
alert("密码不能为空");
login.pwd.focus();
return false;
}
}
-->
</script>
</head><body><form name="login" action="?in=login" method="post" onsubmit="return check();">
<ul id="my">
<li>用户:<input type="text" name="user" size="10" /></li>
<li>密码:<input type="password" name="pwd" size="10" /></li>
<li><input type="submit" name="submit" value="登陆" /></li>
</ul>
</form>
<?php
}else{
?>
<a href='?out=login'>退出</a>
<?php
}
?>
</body>
</html>