1

I am trying to import google contacts using a file called index.php but the result is not as expected - also there are no errors - Hence, I have decided to use the error handling function shown on stack overflow on this link below: PHP's white screen of death

The code is as follows:

<?php

// ----------------------------------------------------------------------------------------------------
// - Display Errors
// ----------------------------------------------------------------------------------------------------
ini_set('display_errors', 'On');
ini_set('html_errors', 0);

// ----------------------------------------------------------------------------------------------------
// - Error Reporting
// ----------------------------------------------------------------------------------------------------
error_reporting(-1);

// ----------------------------------------------------------------------------------------------------
// - Shutdown Handler
// ----------------------------------------------------------------------------------------------------
function ShutdownHandler()
{
    if(@is_array($error = @error_get_last()))
    {
        return(@call_user_func_array('ErrorHandler', $error));
    };

    return(TRUE);
};

register_shutdown_function('ShutdownHandler');

// ----------------------------------------------------------------------------------------------------
// - Error Handler
// ----------------------------------------------------------------------------------------------------
function ErrorHandler($type, $message, $file, $line)
{
    $_ERRORS = Array(
        0x0001 => 'E_ERROR',
        0x0002 => 'E_WARNING',
        0x0004 => 'E_PARSE',
        0x0008 => 'E_NOTICE',
        0x0010 => 'E_CORE_ERROR',
        0x0020 => 'E_CORE_WARNING',
        0x0040 => 'E_COMPILE_ERROR',
        0x0080 => 'E_COMPILE_WARNING',
        0x0100 => 'E_USER_ERROR',
        0x0200 => 'E_USER_WARNING',
        0x0400 => 'E_USER_NOTICE',
        0x0800 => 'E_STRICT',
        0x1000 => 'E_RECOVERABLE_ERROR',
        0x2000 => 'E_DEPRECATED',
        0x4000 => 'E_USER_DEPRECATED'
    );

    if(!@is_string($name = @array_search($type, @array_flip($_ERRORS))))
    {
        $name = 'E_UNKNOWN';
    };

    return(print(@sprintf("%s Error in file \xBB%s\xAB at line %d: %s\n", $name, @basename($file), $line, $message)));
};

$old_error_handler = set_error_handler("ErrorHandler");

// other php code

?>

My page has 1 line of content from tags shown on it at the moment.

Anyway, the problem is that I do not know where to put this code - in same file ? and how to use it?

Community
  • 1
  • 1
  • 1
    as you can see there is `// other php code` message - so this will be the place to put your code. – violator667 Jul 31 '15 at 07:03
  • There's also something called [`require_once`](https://secure.php.net/manual/en/function.require-once.php)... you have never worked with PHP before, have you? – Siguza Jul 31 '15 at 07:04
  • [violator667](http://stackoverflow.com/users/4428904/violator667) - ok , so what do i do if my code is a mix of html and php code - how to put code together with this error handling - thank you –  Jul 31 '15 at 07:05
  • [Siguza](http://stackoverflow.com/users/2302862/siguza) - yes am a beginner in web - i know there is something called require_once - haven't used it much - thank you –  Jul 31 '15 at 07:07
  • You should start by reading the manual and understanding the code before copy/pasting everything you see. It's better to understand and know than to think and assume. – Darren Jul 31 '15 at 07:08
  • @KnowMe just make sure this code is above yours and that php code is always between `` marks. I think you should first experiment with something simple - even force some errors to see how it works as Darren said, then practice with something bigger. – violator667 Jul 31 '15 at 07:16
  • [Darren](http://stackoverflow.com/users/2518525/darren) - which manual should I read - thank you –  Jul 31 '15 at 07:17
  • Do I need to call the function somewhere then [Darren](http://stackoverflow.com/users/2518525/darren), [violator667](http://stackoverflow.com/users/4428904/violator667), [Siguza](http://stackoverflow.com/users/2302862/siguza), [MaggsWeb](http://stackoverflow.com/users/4163162/maggsweb) –  Jul 31 '15 at 07:41

1 Answers1

0

If this function is working correctly, then it will print a nicely formatted error message to the browser. The code should all sit at the top of your PHP page.

My advice : If you dont understand it - dont use it. The following lines (at the top of your PHP file) should be enough to display errors:

ini_set('display_errors', 'On');
error_reporting(-1);
MaggsWeb
  • 3,018
  • 1
  • 13
  • 23