PHP页面是空白的,源代码是空的

时间:2015-06-17 19:03:02

标签: php html

当我在浏览器中打开它时,PHP文件是空白的。此外,当我打开源代码时,它也是空的。

这是 tutorial 我正在关注

以下是代码:

<?php

error_reporting(E_ALL ^ E_NOTICE);

?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Member System - Register</title>
</head>
<body>
<?php

if ($_POST['registerbtn']) {
    $getuser = $_POST['user'];
    $getemail = $_POST['email'];
    $getpass = $_POST['pass'];
    $getconfirmpass = $_POST['confirmpass'];

    if ($getuser) {
        if ($getemail) {
            if ($getpass) {
                if ($getconfirmpass) {
                    if ($getpass === $getconfirmpass) {
                        if (strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, ".")) {
                            require("./connect.php");

                            $query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
                            $numrows = mysql_num_rows($query);
                            if ($numrows == 0) {
                                $query = mysql_query("SELECT * FROM users WHERE email='$getemail'");
                                $numrows = mysql_num_rows($query);
                                if ($numrows == 0) {

                                    $password = md5 (md5("kjfiufj".$getpass."Fjf56fj"));
                                    $date = date("F d, Y");
                                    $code = md5(rand());

                                    mysql_query("INSERT INTO users VALUES (
                                        '', '$getuser', '$password', '$getemail', '0', '$code', '$date'
                                    )");

                                    $query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
                                    $numrows = mysql_num_rows($query);
                                    if ($numrows == 1) {

                                        $site = "http://localhost/PHP Projects/Member System";
                                        $webmaster = "Askman <donotreply@askmanproducts.com>";
                                        $headers = "From: $webmaster";
                                        $subject = "Activate Your New Account!";
                                        $message = "Thanks for regisntering. Click the link below to activate your account!\n";
                                        $message .= "$site/activate?user=$getuser&code=$code\n";
                                        $message .= "You must activate your account to login.";

                                        if (mail($getemail, $subject, $message, $headers)){
                                            $errormsg = "You have been registered. You must activate your account from the activation link sent to <b>$getemail</b>";
                                            $getuser = "";
                                            $getemail = "";
                                        }
                                        else 
                                            $errormsg = "An error has occured. Your activation email was not sent.";

                                    }
                                    else
                                        $errormsg = "An error has occured. Your account was not created.";

                                }
                                else
                                    $errormsg = "There is already a user with that email.";
                            }
                            else
                                $errormsg = "There is already a user with that username.";

                            mysql_close();
                        }
                        else
                            $errormsg = "You must enter a valid email address to register.";
                    }
                    else
                        $errormsg = "Your passwords did not match.";
                }
                else 
                    $errormsg = "You must confirm your password to register.";
            }
            else
                $errormsg = "You must enter your password to register.";
        }
        else
            $errormsg = "You must enter your email to register.";
    }
    else 
        $errormsg = "You must enter your username to register.";

}

$form = "<form action='./register' method='post'>
<table>
<tr>
    <td</td>
    <td><font color='red'>$errormsg</font></td>
</tr>
<tr>
    <td>Username:</td>
    <td><input type='text' name='user' value='$getuser' /></td>
</tr>
<tr>
    <td>Email:</td>
    <td><input type='text' name='email' value='$getemail' /></td>
</tr>
<tr>
    <td>Password:</td>
    <td><input type='password' name='pass' value='' /></td>
</tr>
<tr>
    <td>Confirm Password:</td>
    <td><input type='password' name='confirmpass' value='' /></td>
</tr>
<tr>
    <td></td>
    <td><input type='submit' name='registerbtn' value='Register' /></td>
</tr>
</table>
</form>";

echo $form;

?>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

你在这一行上有错误 if (strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, ".")) {

必须是if ((strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, "."))) {

另外,浏览器中的源代码会显示html代码而不是php php是服务器端,因此它的代码在服务器内,浏览器无法看到 php代码

完整代码

<?php

error_reporting(E_ALL ^ E_NOTICE);

?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Member System - Register</title>
</head>
<body>
<?php

if ($_POST['registerbtn']) {
    $getuser = $_POST['user'];
    $getemail = $_POST['email'];
    $getpass = $_POST['pass'];
    $getconfirmpass = $_POST['confirmpass'];

    if ($getuser) {
        if ($getemail) {
            if ($getpass) {
                if ($getconfirmpass) {
                    if ($getpass === $getconfirmpass) {
                        if ((strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, "."))) {
                            require("./connect.php");

                            $query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
                            $numrows = mysql_num_rows($query);
                            if ($numrows == 0) {
                                $query = mysql_query("SELECT * FROM users WHERE email='$getemail'");
                                $numrows = mysql_num_rows($query);
                                if ($numrows == 0) {

                                    $password = md5 (md5("kjfiufj".$getpass."Fjf56fj"));
                                    $date = date("F d, Y");
                                    $code = md5(rand());

                                    mysql_query("INSERT INTO users VALUES (
                                        '', '$getuser', '$password', '$getemail', '0', '$code', '$date'
                                    )");

                                    $query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
                                    $numrows = mysql_num_rows($query);
                                    if ($numrows == 1) {

                                        $site = "http://localhost/PHP Projects/Member System";
                                        $webmaster = "Askman <donotreply@askmanproducts.com>";
                                        $headers = "From: $webmaster";
                                        $subject = "Activate Your New Account!";
                                        $message = "Thanks for regisntering. Click the link below to activate your account!\n";
                                        $message .= "$site/activate?user=$getuser&code=$code\n";
                                        $message .= "You must activate your account to login.";

                                        if (mail($getemail, $subject, $message, $headers)){
                                            $errormsg = "You have been registered. You must activate your account from the activation link sent to <b>$getemail</b>";
                                            $getuser = "";
                                            $getemail = "";
                                        }
                                        else
                                            $errormsg = "An error has occured. Your activation email was not sent.";

                                    }
                                    else
                                        $errormsg = "An error has occured. Your account was not created.";

                                }
                                else
                                    $errormsg = "There is already a user with that email.";
                            }
                            else
                                $errormsg = "There is already a user with that username.";

                            mysql_close();
                        }
                        else
                            $errormsg = "You must enter a valid email address to register.";
                    }
                    else
                        $errormsg = "Your passwords did not match.";
                }
                else
                    $errormsg = "You must confirm your password to register.";
            }
            else
                $errormsg = "You must enter your password to register.";
        }
        else
            $errormsg = "You must enter your email to register.";
    }
    else
        $errormsg = "You must enter your username to register.";

}

$form = "<form action='./register' method='post'>
<table>
<tr>
    <td</td>
    <td><font color='red'>$errormsg</font></td>
</tr>
<tr>
    <td>Username:</td>
    <td><input type='text' name='user' value='$getuser' /></td>
</tr>
<tr>
    <td>Email:</td>
    <td><input type='text' name='email' value='$getemail' /></td>
</tr>
<tr>
    <td>Password:</td>
    <td><input type='password' name='pass' value='' /></td>
</tr>
<tr>
    <td>Confirm Password:</td>
    <td><input type='password' name='confirmpass' value='' /></td>
</tr>
<tr>
    <td></td>
    <td><input type='submit' name='registerbtn' value='Register' /></td>
</tr>
</table>
</form>";

echo $form;

?>
</body>
</html>