PHP //白屏死机,报告所有错误

Posted

技术标签:

【中文标题】PHP //白屏死机,报告所有错误【英文标题】:PHP // White screen of death with all errors reporting on 【发布时间】:2015-11-24 02:03:01 【问题描述】:

尽管我尝试了所有关于显示错误的方法,但我仍然出现白屏死机。

请注意,我正在使用 XAMPP 开发网站。 还有什么我可以做的吗?也看看我的代码,因为我不知道它是否有效。

代码如下:

<?php

error_reporting(-1);  // Have PHP complain about absolutely everything 
$conf['error_level'] = 2;  // Show all messages on your screen, 2 = ERROR_REPORTING_DISPLAY_ALL.
ini_set('display_errors', TRUE);  // These lines just give you content on WSOD pages.
ini_set('display_startup_errors', TRUE);

require("dbconn.php");
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

    $Username   =   $_POST['username']; #Username
    $Password   =   $_POST['password']; #Password

function InsrtUser()

    global $Username,$Password;
    #Egxwrish stoixeiwn
    $hashed_pass = PASSWORD_HASH($Password, PASSWORD_DEFAULT);
    $query = "INSERT INTO users (username,password) VALUES (:username, :password)";
    $data = $mysqli->prepare($query);
    $data->execute(array(':username'=>$Username, ':password'=>$hashed_pass));
    if($data->rowCount() > 0)
    
        return "YOUR REGISTRATION IS COMPLETED...";
    


function Register()

    global $Username,$Password;
    if(!empty($Username))   //checking the 'username' name which is from register.html, if is it empty or have some text
        
                $query = ("SELECT * FROM users WHERE username = :username");
                $query = $mysqli->prepare($query);
                $query->execute(array(':username'=>$Username));
                if($query->rowCount() == 0)
            
                $msg = InsrtUser();
                echo $msg;
            
            else 
                echo "SORRY...YOU ARE ALREADY registerED USER...!";
                die();
            

        


if(isset($_POST['submit']))

    //User registration
    Register();
    echo "Your account has been created successfully. \\n Thank you for joined us!";
    $msgSuccess = "Your account has been created successfully. \\n Thank you for joined us!";
        echo 
            "<script>
            alert('$msgSuccess');
            window.location.href='../index.php';
            </script>";


?>

【问题讨论】:

使用error_reporting(E_ALL) 而不是error_reporting(-1)。另外 - 检查您的错误日志文件。有什么有趣的吗? 可能不是死屏而是$_POST['submit']没有设置? @uri2x E_ALL 等同于 -1 并显示所有错误。 PHP 手册:Passing in the value -1 will show every possible error, even when new levels and constants are added in future PHP versions. The E_ALL constant also behaves this way as of PHP 5.4. @CharlotteDunois 够公平的。我仍然更喜欢 E_ALL 代码可读性。 谢谢你们,我也试过 E_ALL。 @chris85 发现的问题。这是关于 $_POST['submit'] 的。 【参考方案1】:

这实际上不是您遇到的死亡屏幕场景。如果设置了$_POST['submit'],您只会输出内容。如果未设置,则不会输出任何内容,因此预期值是白屏(无内容),这就是您得到的值。

我认为问题在于您的提交按钮没有名称属性submit

将来添加一个 else 也将帮助您调试这些..

if(isset($_POST['submit']))

    //User registration
    Register();
    echo "Your account has been created successfully. \\n Thank you for joined us!";
    $msgSuccess = "Your account has been created successfully. \\n Thank you for joined us!";
        echo 
            "<script>
            alert('$msgSuccess');
            window.location.href='../index.php';
            </script>";

 else 
    echo 'The submit button is not set :(';

【讨论】:

以上是关于PHP //白屏死机,报告所有错误的主要内容,如果未能解决你的问题,请参考以下文章

大型 HTML 显示空白页面(WSOD - 白屏死机) - PHP

白屏死机 - Android 上的 Ionic 2

电脑卡住了白屏怎么办

如何在 ASP.NET MVC 中调试死机白屏

如何在laravel 4上显示错误?

如何调试 PHP WSOD?