Solved

Why error_reporting in browser KO?

Posted on 2014-11-29
13
137 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Are you sure there is any errors?
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 58

Expert Comment

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

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Under Loaded Configuration File it will show where it is being loaded from
0
 
LVL 1

Author Closing Comment

by:Richard Coffre
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

763 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

6 Experts available now in Live!

Get 1:1 Help Now