简体   繁体   English

如何在Firefox中的网页上显示php错误消息?

[英]how to display php error message on web page in firefox?

Here is my simple codes file in /var/www/read.php : 这是我在/var/www/read.php中的简单代码文件:

error_reporting(E_ALL);
<?php
    echo hello"
?> 

I ran across the error reporting when to run `php /var/www/read.php ' on debian console. 我跑过错误报告何时在debian控制台上运行`php /var/www/read.php'。

PHP Parse error:  syntax error, unexpected '"', expecting ',' or ';' in /var/www/read.php on line 3

But there is no error reporting in web page when to input 127.0.0.1/read.php in firefox. 但是在火狐中输入127.0.0.1/read.php时,网页中没有错误报告。

I have set the values in php.ini as following: 我在php.ini中设置了如下值:

error_reporting = E_ALL & ~E_NOTICE    
display_errors = On  

It is no use for me to restart apache2 with command : 用命令重新启动apache2对我没用

service apache2 restart

Here is my phpinfo message. 这是我的phpinfo消息。 It is no use to add two lines in my read.php file,no error message reported in my firefox.How can i fix it?My system is debian7+php . 在我的read.php文件中添加两行是没有用的,我的firefox中没有报告错误消息。我可以修复它吗?我的系统是debian7 + php。

<?php
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    echo hello"
?> 

find  /  -name  'php.ini'
/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini

The problem solved according to PHP doesn't show any kind of errors 根据PHP解决的问题没有显示任何类型的错误

在此输入图像描述在此输入图像描述在此输入图像描述

First, the error_reporting() function should be moved inside the <?php ?> tags. 首先,应该在<?php ?>标记内移动error_reporting()函数。

There are usually two php.ini files in a typical setup (One used by the webserver, other one used by the command line). 典型设置中通常有两个php.ini文件(一个由Web服务器使用,另一个由命令行使用)。

On a unix distribution, it is usually located somewhere below the /etc/php folder, like that for example /etc/php/apache2/php.ini . 在unix发行版中,它通常位于/etc/php文件夹下面的某个/etc/php/apache2/php.ini ,例如/etc/php/apache2/php.ini

To be sure what configuration file is loaded for PHP by the webserver, do a simple phpinfo(); 为了确保Web服务器为PHP加载了哪个配置文件,请执行一个简单的phpinfo(); in a webpage and just search for configuration file . 在网页中只搜索configuration file

If you modify the one used by your websever, make sure to restart Apache afterwards, so it loads the new configuration. 如果修改了websever使用的那个,请确保之后重新启动Apache,以便加载新配置。

If you want to enforce programmatically setting, you can use the ini_set function. 如果要强制执行以编程方式设置,可以使用ini_set函数。

In your case, if you want to see any error on the page. 在您的情况下,如果您想在页面上看到任何错误。

<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);

foobar();

Update : 更新:

Adding ini_set('display_errors', 1); 添加ini_set('display_errors', 1); won't do anything if there is a syntax error in the page, because the syntax error is thrown before the execution of the script. 如果页面中存在语法错误,则不会执行任何操作,因为在执行脚本之前会抛出语法错误。 Try to create another type of error, eg call an unknown function instead, and you should see it. 尝试创建另一种类型的错误,例如调用未知函数,你应该看到它。

Use error_reporting(1); 使用error_reporting(1); or error_reporting(TRUE); error_reporting(TRUE); and make sure no where you have disabled anything pertaining to error reporting 并确保没有禁用任何与错误报告有关的内容

add this code in your php file 在您的php文件中添加此代码

// Report all PHP errors
error_reporting(-1);
//To show errors
ini_set('display_errors', 1);
error_reporting(E_ALL);

//To hide error 
ini_set('display_errors', 0);

You also set this is in a common php file or in working file.. 你还设置这是一个常见的PHP文件或工作文件..

You should see which php.ini is read by Apache. 你应该看看Apache读取了哪些php.ini。 It is common for console to use a different php.ini than Apache. 控制台使用与Apache不同的php.ini是很常见的。

You can phpinfo() and see which configuration file is being read by Apache. 您可以使用phpinfo()查看Apache正在读取的配置文件。

However, at the beginning of the read.php file add the following line: 但是,在read.php文件的开头添加以下行:

init_set("display_errors", 1);

PHP has a nasty habit of giving the white screen of mystery when the error is syntax related. 当错误与语法相关时,PHP有一种令人讨厌的习惯,即让白屏变得神秘。 To get around this you can use the include function: 要解决此问题,您可以使用include函数:

<?php
    ini_set('display_errors',1); 
    error_reporting(E_ALL);
    include "/var/www/read.php";
?> 

Now the syntax error is no longer in the first page and PHP can "compile" it will give you an error message about the broken page. 现在语法错误不再出现在第一页中,PHP可以“编译”它会给你一个关于破坏页面的错误消息。

There are a couple of issues with the first code sample which should look like this: 第一个代码示例有几个问题应该如下所示:

<?php
    error_reporting(E_ALL);
    echo "hello";
?> 

First error reporting directives like all PHP code needs to be inside the PHP code tags. 像所有PHP代码一样的第一个错误报告指令需要在PHP代码标记内。 This should result in the code simply ending up on the page in Firefox which is not what you want. 这应该导致代码简单地在Firefox中的页面上结束,这不是你想要的。

Second echo acts on a string which should start and end with a quote mark. 第二个echo作用于一个字符串,该字符串应以引号开头和结尾。 This is a syntax error and at the heart of the no error message problem. 这是语法错误,是无错误消息问题的核心。

Third all line must end with a semi colon (with the exception of a few block level commands). 第三行必须以半冒号结束(除少数块级命令外)。 If in doubt... This is actually not your problem and you code will run without it as long as the code section terminates with a ?> as PHP will assume ; 如果有疑问......这实际上不是你的问题,你的代码将在没有它的情况下运行,只要代码部分以?>终止,如PHP所假设的那样; for you. 为了你。 However get intot he habit of putting you ; 然而,他习惯性地把你带走; in place every time and you will not be tripped up by it later. 每次都到位,以后你不会被它绊倒。

Now assuming that you are not on a host running in safe mode then you can turn on error reporting at the ini level in your code too 现在假设您不在以安全模式运行的主机上,那么您也可以在代码中的ini级别打开错误报告

<?php
    ini_set('display_errors',1); 
    error_reporting(E_ALL);
    echo "hello world";
    unknownfunction() // this will throw errors
?> 

Judging by the fact that you have full control of the system I would say that you should know if you put safemode on. 从你完全控制系统的事实来看,我会说你应该知道你是否安装了安全模式。 Also I see that you tried the above ini directive to no available (this is due to the syntax issue that I explained at the start of the answer). 另外我看到你尝试了上面的ini指令没有可用(这是由于我在答案开始时解释的语法问题)。

Here is some further reading that might be of interest: 以下是可能感兴趣的一些进一步阅读:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM