-1

我正在创建一个简单的网页 PHP 和 MySQL 联合登录系统。我遇到了一个问题,简而言之,我无法登录。如果您可以快速查看我的代码,那就太好了!我更像是一名 HTML/CSS 开发人员。谢谢!

好的,这是我的登录页面(login.php),

<?php
session_start();
require_once 'Membership.php';
$membership = new Membership();

// If the user clicks the "Log Out" link on the index page.
if(isset($_GET['status']) && $_GET['status'] == 'loggedout') {
    $membership->log_User_Out();
}

// Did the user enter a password/username and click submit?
if($_POST && !empty($_POST['username']) && !empty($_POST['pwd'])) {
    $response = $membership->validate_User($_POST['username'], $_POST['pwd']);
}


?>
<!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 Form</title>
<link href="style-login.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
    $("#cerceve").hide().fadeIn(500);
    $(".show").hide();
    $(".close").click(function(){
        $("#cerceve").hide(500);
        $(".show").fadeIn(500);
    });
    $(".show").click(function(){
        $("#cerceve").fadeIn(500);
        $(".show").hide(500);
    });
});
</script>
</head>
<body>
<div id="cerceve">
  <div class="header"><div class="text" style="float:left">Login Form</div><div class="close" style="float:right;margin-right:20px;cursor:pointer;">x</div></div>
<div class="formbody">
<script type="text/javascript" src="sha512.js"></script>
<script type="text/javascript" src="js/forms.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<form name="loginForm" method="post" action="">
<input type="text" input name="username" placeholder="Email" class="text" style="background:url(images/username.png) no-repeat;" />
<input type="password" input name="pwd" placeholder="••••••••••••" class="text" style="background:url(images/password.png) no-repeat;" />
<input type="submit" value="Sign In" class="submit" style="background:url(images/login.png) no-repeat;" id="submit" name="submit" /><a href="#">Lost your password?</a>
</form>


</div>
</div>
</body>
</html>

这是其他几个 PHP 文档,(它们要短得多)..

该文件名为“Membership.php”

<?php

require 'Mysql.php';

class Membership {

    function validate_user($un, $pwd) {
        $mysql = New Mysql();
        $ensure_credentials = $mysql->verify_Username_and_Pass($un, md5($pwd));

        if($ensure_credentials) {
            $_SESSION['status'] = 'authorized';
            header("location: index.php");
        } else return "Please enter a correct username and password";

    } 

    function log_User_Out() {
        if(isset($_SESSION['status'])) {
            unset($_SESSION['status']);

            if(isset($_COOKIE[session_name()])) 
                setcookie(session_name(), '', time() - 1000);
                session_destroy();
        }
    }

    function confirm_Member() {
        session_start();
        if($_SESSION['status'] !='authorized') header("location: success.php");
    }

}

和.. 一个名为“MySQL.php”的文件

<?php

// Define constants here

define('DB_SERVER', 'localhost');
define('DB_USER', 'noahtech_dbuser');
define('DB_PASSWORD', 'dbuseraccess');
define('DB_NAME', 'noahtech_secure');

和一个名为“Constants.php”的重复 PHP 文档

<?php

// Define constants here

define('DB_SERVER', 'localhost');
define('DB_USER', 'noahtech_dbuser');
define('DB_PASSWORD', 'dbuseraccess');
define('DB_NAME', 'noahtech_secure');

请帮忙!我是否正确格式化了“定义”数据库服务器、用户、密码和名称?

4

1 回答 1

1

标签没有属性input nameinput只是name

input name="username"
input name="pwd"

应该

name="username"
name="pwd"

编辑1:

您还应该检查用户是否按下submit按钮。所以

if($_POST && !empty($_POST['username']) && !empty($_POST['pwd'])) {
    $response = $membership->validate_User($_POST['username'], $_POST['pwd']);
}

应该

if (isset($_POST['sumbit'])){
if($_POST && !empty($_POST['username']) && !empty($_POST['pwd'])) {
    $response = $membership->validate_User($_POST['username'], $_POST['pwd']);
}
}
于 2013-04-27T08:18:10.970 回答