Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make PHP errors in text instead of HTML [duplicate]

Tags:

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

Error I am trying to avoid

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.

like image 419
Xander Luciano Avatar asked Jun 03 '12 08:06

Xander Luciano


1 Answers

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.

like image 169
Gordon Avatar answered Oct 07 '22 22:10

Gordon