2013-10-02 52 views
0

的形式为:

<form action="/HW2/controllers/login.php" id = "login-box" method = "post"> 
     Username: <input type="text" name='user'><br> 
     Password: <input type="text" name='pwd'><br> 
     <input type="submit"> 
    </form> 

行动:“邮报数据未发送”

<?php 
require("../config/config.php"); 
if(isset($_POST['user']) && isset($_POST['pwd'])){ 
    if(strcmp($_POST['user'], USERNAME) == 0 && strcmp($_POST['pwd'], 
     PASSWORD) == 0){ 
     session_start(); 
     $_SESSION['logon'] = true; 
     echo "success"; 
     //header("location: /HW2/index.php?view=loggedin"); 
    }else{ 
     print_r("Sorry, your username and/or password are invalid. Try Again?"); 
     //header("location: /HW2/index.php?view=loginPage"); 
     } 
}else{ 
    print_r("Post data not sent."); 
} 
?> 

我已经试过许多不同的方法,所有结果(又名“未定义的索引:“如果我尝试访问$ _POST值)试图找到我现在搞砸了好几个小时,任何帮助表示赞赏,我是一个完全在PHP中磨合,它可能是一个令人难以置信的简单和愚蠢。

在此先感谢!

+0

你应该在包含config.php文件之前进行会话。 – tinybyte

+0

您的表单适合我。也许,在config.php中有些错误。尝试在'if'之前移除它和var_dump($ _ POST); – user4035

+0

顺便说一下,你似乎在本地存储一个未加密的密码(在你的PASSWORD常量中)。如果您想要创建安全的应用程序,您不应该访问用户的未加密密码。 –

回答

0

我认为没有必要使用最后的 “其他”

只使用

if(isset($_POST['user']) && isset($_POST['pwd'])){ 
if(strcmp($_POST['user'], USERNAME) == 0 && strcmp($_POST['pwd'], 
    PASSWORD) == 0){ 
    session_start(); 
    $_SESSION['logon'] = true; 
    echo "success"; 
    //header("location: /HW2/index.php?view=loggedin"); 
}else{ 
    print_r("Sorry, your username and/or password are invalid. Try Again?"); 
    //header("location: /HW2/index.php?view=loginPage"); 
    } 

}

0
<?php 
error_reporting(E_ALL^E_NOTICE); 

require("../config/config.php"); 
if(isset($_POST['user']) && isset($_POST['pwd'])){ 
    if(strcmp($_POST['user'], USERNAME) == 0 && strcmp($_POST['pwd'], 
     PASSWORD) == 0){ 
     session_start(); 
     $_SESSION['logon'] = true; 
     echo "success"; 
     //header("location: /HW2/index.php?view=loggedin"); 
    }else{ 
     print_r("Sorry, your username and/or password are invalid. Try Again?"); 
     //header("location: /HW2/index.php?view=loginPage"); 
     } 
}else{ 
    print_r("Post data not sent."); 
} 
?> 

使用error_reporting(E_ALL^E_NOTICE);显示错误,但隐藏通知。未定义的索引显示$ _POST变量被调用时没有值,所以这是第一个选项。第二个选择是修改代码。

的观点:

<form action="/HW2/controllers/login.php" id = "login-box" method = "post"> 
     Username: <input type="text" name='user'><br> 
     Password: <input type="text" name='pwd'><br> 
     <input type="submit" name = "submit" value = "Submit"> 
    </form> 

PHP代码:

<?php 
require("../config/config.php"); 
if(isset($_POST['submit'])){ 
    if(strcmp($_POST['user'], USERNAME) == 0 && strcmp($_POST['pwd'], 
     PASSWORD) == 0){ 
     session_start(); 
     $_SESSION['logon'] = true; 
     echo "success"; 
     //header("location: /HW2/index.php?view=loggedin"); 
    }else{ 
     print_r("Sorry, your username and/or password are invalid. Try Again?"); 
     //header("location: /HW2/index.php?view=loginPage"); 
     } 
}else{ 
    print_r("Post data not sent."); 
}?> 
0

嘿感谢您的回答大家,事实证明,我的代码是工作的罚款后,我重新启动我的电脑,倒头便睡。

我的猜测是,无论是铬或apache错误处理$ _POST变量,但我不是很有经验,所以我只是spitballing。无论哪种方式我的代码正在做我想要的东西。

感谢您的帮助!