如何使文本中的PHP错误而不是HTML [英] How to make PHP errors in text instead of HTML

查看:98
本文介绍了如何使文本中的PHP错误而不是HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:


html_errors boolean



关闭错误消息中的HTML标签。 HTML错误的新格式产生可点击的消息,将消息引导到描述错误或功能的页面,导致错误。这些引用受docref_root和docref_ext影响。


设置为可设置作为 PHP_INI_ALL ,这意味着任何地方,包括您的脚本。所以要禁用html错误,

  ini_set('html_errors',false); 

在脚本开头。


Possible Duplicate:
How can I tell PHP to dump exceptions as raw text instead of HTML?

I am trying to make a login script using C# and php and I plan on selling it as a 1 click install so I need it to be error proof. I am purposely trying to make mistakes in the setup, but whenever my php script has a mistake it has an HTML block output with the error when I just want a string output(refer to image).

Heres the code I am using

// We will now set up our MySQL database login. The values should be self-explanatory. 
$sqlhost = "localhost";
$sqlusername = "unity";
$sqlpassword = "mypass123";

//we will now connect to our database
$sqlcon = mysql_connect($sqlhost, $sqlusername, $sqlpassword) or die("Could not connect to database: " . mysql_error());

When I have all the information it works fine and the rest of the code runs without an error. But if my password is wrong or the user doesn't have access then I get this error

I am retrieved the information from this page and it needs to be sent as plan text to be displayed properly. What I mean by this is that any HTML tags like <div>, <br>, <a>, etc and just generally makes the text output look bad. I want this to just display the text at the bottom the page because that logs the error itself. I dont need it to log twice and I dont need it to be formatted fancy. I need it in plain readable text so that if a user has an error they can send me the short text and I will be able to walk them through the fix.

解决方案

Whether PHP displays plain text or html errors depends on your php.ini configuration:

html_errors boolean

Turn off HTML tags in error messages. The new format for HTML errors produces clickable messages that direct the user to a page describing the error or function in causing the error. These references are affected by docref_root and docref_ext.

The setting is settable as PHP_INI_ALL, which means anywhere, including your script. So to disable html errors do

ini_set('html_errors', false);

at the beginning of your script.

这篇关于如何使文本中的PHP错误而不是HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆