PHP 登录脚本导致空白页

标签 php html css sql apache

所以我正在为我的网站开发一个 PHP/SQL 登录脚本。服务器是运行 Apache 的 UNIX 系统,并安装了 PHP,这一点我很确定。我设置了 SQL 数据库,并将我的 PHP 代码分成几个部分。

http://www.woodlandastronomy.org/login.php :

<?php
    session_start();
    require_once 'http://www.woodlandastronomy.org/cgi-bin/classes/membership.php';
    $membership = new Membership()

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

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="description" content="Woodland Astronomy Club Website">
        <meta name="keywords" content="Woodland, Astronomy, Club, Website, Moss, Lake, Neighborhood, Astronomical, Association">
        <link rel="stylesheet" href="wasmain.css">
        <link rel="icon" href="http://www.woodlandastronomy.org/favicon.ico" type="image/x-icon">
        <script type="text/javascript" src="script1.js"></script>
        <title>Woodland Astronomy Club - Home</title>
    </head>

    <body>
        <div id="container">
            <div id="header">
                <img src="IMG_9897 2 (3) copy.jpg" alt="we has a issue, sorrys!1!!!" width="100%" height="200px">
                <div id="linkbar">
                    <p class="linkbarbutton">
                        <b><a class="linkbarlink" href="http://www.woodlandastronomy.org/index.html">Home</a></b>
                    </p>
                    <p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/aboutus.html">About Us</a></b></p>
                    <p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/events.html">Club Events</a></b></p>
                    <p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/eventpix.html">Club Photos</a></b></p>
                    <p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/astropix.html">Astrophotography</a></b></p>
                    <p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.weatherlink.com/user/theweathercat/" target="_blank">Weather Station</a></b></p>
                    <p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/contact.html">Contact Us</a></b></p>
                    <p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/links.html">External Links</a></b></p>
                    <p class="linkbarbutton"><b><a class="linkbarlink" href="http://www.woodlandastronomy.org/members.html">Members</a></b></p>
                </div>
            </div>
            <div id="content">
                <div id="fluffy"></div>
                <div id="login">
                    <form method="post" action="">
                        <h2 class="yellowlabel">Login <small>Enter Your Credentials</small></h2>
                        <p class="yellowlabel">
                            <label for="username" >Username: </label>
                            <input type="text" name="username">
                        </p>
                        <p class="yellowlabel">
                            <label for="password">Password: </label>
                            <input type="password" name="pwd">
                        </p>
                        <p>
                            <input type="submit" id="submit" value="Login" name="submit">
                        </p>
                    </form>
                    <?php
                        if(isset($response)) echo "<h4 class='alert'>" . $response . "</h4>";
                    ?>
                </div>
            </div>
        </div>
    </body>
 </html>

然后,

http://www.woodlandastronomy.org/cgi-bin/classes/membership.php :

<?php
    require 'http://www.woodlandastronomy.org/cgi-bin/classes/Mysql.php';

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

            if($ensure_credentials) {
                $_SESSION['status'] = 'authorized';
                header("location: http://www.woodlandastronomy.org/members.html");
            } else return "Please enter a correct username and password";
        }
    }
?>

然后,

http://www.woodlandastronomy.org/cgi-bin/classes/mysql.php :

<?php
    require_once 'http://www.woodlandastronomy.org/cgi-bin/classes/constants.php';

    class Mysql {
        private $conn;

        function __construct() {
            $this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or 
            die('There was a problem connecting to the database.');
        }

        function verify_Username_and_Pass($un, $pwd) {

            $query = "SELECT *
                      FROM Membership
                      WHERE username = ? AND password = ?
                      LIMIT 1";

            if($stmt = this->conn->prepare($query)) {
                $stmt->bind_param('ss', $un, $pwd);
                $stmt->execute();

                if($stmt->fetch()) {
                    $stmt->close();
                    return true;        
                }
            }
        }
    }
?>

最后,

http://www.woodlandastronomy.org/cgi-bin/classes/constants.php :

 <?php
    define('DB_SERVER', 'localhost');
    define('DB_USER', '/*I didn't want to put my database credentials on the web, you understand...');
    define('DB_PASSWORD', '');
    define('DB_NAME', 'Member');
?>

所以之前,页面是完全空白的,但那是包含文件中的语法错误。找到这个之后,我开始收到错误消息,告诉我 PHP 无法连接到 MySQL 数据库。经过更多工作后,我设法完全摆脱了错误消息,但现在当我单击“登录”时,它只是尝试加载,直到浏览器最终显示消息“与服务器的连接已重置。”

我迷路了。我的邻居擅长 PHP,但他从今天下午起就出城了,我似乎无法自己解决这个问题。

如果有人能告诉我我做错了什么,那就太好了。

抱歉这个问题太长了。

谢谢,哈罗德

最佳答案

我会建议使用 XDebug 和/或打开一些错误跟踪。

ini_set('display_errors', '1');  

关于PHP 登录脚本导致空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18198065/

相关文章:

html - CSS 中是否可以为具有 `display:block` 子元素的元素添加轮廓/颜色?

html - 创建 css 文件并应用样式

php - 如何跟踪 IP 以阻止恶意用户?

php - 如何创建每天生成新文本的 PHP 脚本?

php - 如何检查用户是否登录?

java - Internet Explorer 和 JSP 中的基本 URL

html - Fabric UI 复选框标签对齐

jquery更改通配符的CSS属性

jQuery 导航插件刷新整个页面。我该如何解决

php - 在 PHP 中重新初始化静态成员