前两天我写了一个很简单的登陆页面,但是在我这编译没通过。核对了一下源码,没有错误。但就是运行不出现结果,也不报错。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>

解决方案 »

  1.   

    直接用session不好么 
    哦 还是高手来指点吧
      

  2.   

    其实没啥问题,就是你那个md5那个加密的内容你是不是不知道啊,你换成444bcb3a3fcf8389296c49467f27e1d6,这个是“ok”,这样应该可以
      

  3.   

     哎  你验证的js有点问题
    加上 login.submit();
      

  4.   


    <?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 所以那个出错会一直显示 给一个判断 提交之后显示 比较好。
      

  5.   

    楼主干嘛要用COOKIE,SESSION简单又好用!
      

  6.   

    你这样把程序写死了,user就只有admin吗?你的check user呢?
      

  7.   

    lz 没问题呀~~是不是那个md5你不知呀,换成e10adc3949ba59abbe56e057f20f883e试试
    user : admin
    pwd :123456
      

  8.   

    那个MD5没问题 密码是php,这只是一个测试文档,所以在学cookie  我也知道session好。
    我的环境是xampp。 php版本是5.3.1。js只是做了一个简单的判断。
    谢谢dingwww421317017
    回去试试 谢谢各位
      

  9.   


    var_dump($_COOKIE);//跟踪COOKIE
      

  10.   

    你的逻辑可能有点问题 刚开始运行代码时$_COOKIE['cookie']是没有的吧?$_COOKIE['cookie']不存在怎么能判断$_COOKIE['cookie']的值是否等于'ok'呢?
      

  11.   

    不知道你要的是不是这样的结果<!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>
    <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>
      

  12.   

    action="url" 要给指定传值的地址
      

  13.   

    代码改为:<?php
     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>
      

  14.   

    csdn改版后连行号都没有 晕