Solved

Why error_reporting in browser KO?

Posted on 2014-11-29
13
139 Views
Last Modified: 2014-12-04
Hi all,

Reading Ray Paseur advices, I'm trying to set error_reporting to ALL for my PHP installation.
I'm using MAMP.

My PHP version is 5.6.2. so I've updated the php.ini located at: /Applications/MAMP/conf/php5.6.2 by uncommenting the line "error_reporting  =  E_ALL"
In addition, I've updated display_errors by setting it to “On”.

I have restarted the server but nothing appears in the browser.
I can see my error in php_error.log.

Regards,
Richard
0
Comment
Question by:Richard Coffre
  • 5
  • 5
  • 3
13 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40471671
In your site PHP pages (usually the header file as it is the common file) add at the top

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

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40471675
Search the entire php.ini file to be sure you don't have an override of a setting later in the file.  Not sure, but IIRC the settings below will overwrite the settings above.  If you're using htdocs as your web root directory, you can put the php.ini file in the web root htdocs directory.
0
 
LVL 1

Author Comment

by:Richard Coffre
ID: 40471869
Ray,

I checked the entire php.ini file and there is no override.

Gary,

I tested your solution but it fails.

I will continue my investigation.
It should have something preventing for the display.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40471873
Are you sure there is any errors?
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
ID: 40471941
If there are errors in the log, but no corresponding error display, then the errors occurred but did not get displayed.  Question: Did anything get displayed by the scripts that failed?  If you need a predictable test case, PHP trigger_error() can help.

If it helps, you can use this script to find and display the contents of error_log (or similarly named files - just customize it for your installation).  It goes in the WWW root directory and searches everything in the directory tree.

<?php // find_error_log.php
error_reporting(E_ALL);
ob_start();

// PUT THIS SCRIPT IN THE WEB ROOT DIRECTORY
$path = realpath(getcwd());
$plen = strlen($path);

// THE ERROR LOG FILE NAME
$signal = strrev('error_log');


// IF THERE IS A POST-METHOD REQUEST TO DELETE THIS ERROR LOG
if (!empty($_POST['log']))
{
    // MAKE SURE WE ONLY UNLINK THE ERROR LOG FILE
    $test = strrev($_POST['log']);
    if (strpos($test, $signal) === 0)
    {
        unlink($path . $_POST['log']);
        echo '<h3>' . $_POST['log'] . ' Discarded</h3>';
    }
}


// SEE http://php.net/manual/en/class.recursivedirectoryiterator.php#85805
$objs = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);

// UNFORTUNATELY THIS DOES NOT WORK AT PHP 5.4
// var_dump($objs);

// ITERATE OVER THE OBJECTS
foreach($objs as $name => $obj)
{
    // PROCESS THE ERROR LOG ONLY
    $test = strrev($name);
    if (strpos($test, $signal) === 0)
    {
        $name = substr($name, $plen);
        $form = <<<EOD
<form method="post" style="margin:0; padding:0; display:inline;!important">
<b>$name</b>
<input type="submit" value="Discard?" />
<input type="hidden" name="log" value="$name" />
</form>
EOD;
        echo $form;

        // SHOW THE CONTENTS OF THE ERROR LOG
        echo '<pre>';
        print_r(file_get_contents($path . $name));
        echo '</pre>' . PHP_EOL;
    }
}

$out = ob_get_contents();
if (empty($out)) echo '<h3>Good News! No error_log found.</h3>';

Open in new window

0
 
LVL 1

Author Comment

by:Richard Coffre
ID: 40473375
Hi guys,

Ray, I will test your solution later but to answer to Gary, this is what I got from the log file:

[01-Dec-2014 11:56:28 Europe/Berlin] PHP Parse error:  syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in /Users/richardcoffre/Documents/blackhole/Dropbox/dev-web/php/carriers/test-error-reporting.php on line 11

Open in new window


Should it appear in the browse? I think so, mayb I'm wrong.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 58

Expert Comment

by:Gary
ID: 40474376
Post the code in test-error-reporting.php
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40475076
Short answer: Yes, a PHP parse error should be visible in the browser.  Are you running scripts out of something like localhost:8888 to access a directory like htdocs for the web root?  If so, you may be able to put php.ini in the htdocs root directory.
0
 
LVL 1

Author Comment

by:Richard Coffre
ID: 40475574
Hi  guys,

Thank you for your help.

I did them all but failure still be there.

This is my code

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

echo "start";
// This is an error I want to see using error reporting
echo "fff 

?>

Open in new window


And I attached some screenshots to show my settings.
20141202-browser-screenshot.png
20141202-htdocs-location.png
20141202-MAMP-htdocs-settings.png
20141202-php-ini-settings.png
0
 
LVL 58

Expert Comment

by:Gary
ID: 40476248
I suspect you are editing the wrong php.ini file
Do a phpinfo() and check the paths.
0
 
LVL 1

Author Comment

by:Richard Coffre
ID: 40476268
When I did the phpinfo(), the version displayed is 5.6.2 so I took the php.ini located in the 5.6.2 directory.
But I will re-check it asap.
0
 
LVL 58

Accepted Solution

by:
Gary earned 400 total points
ID: 40476281
Under Loaded Configuration File it will show where it is being loaded from
0
 
LVL 1

Author Closing Comment

by:Richard Coffre
ID: 40480741
I use the Gary comment to find the correct location of the php.ini and I used the function trigger_error() provided by Ray to test several cases of cases.

Thank a lot guys.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now