Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8162723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:49:32+00:00 2026-06-06T18:49:32+00:00

m maintaining a project, that has to be compatible through PHP 4.X to 5.2.

  • 0

m maintaining a project, that has to be compatible through PHP 4.X to 5.2. The project as several errors wich are not very well handled.

What I want to do is redirect user to a “nice” error page, and log the error in the database. In order to keep track of the user, the file, and the error message. Here is what I’ve tried so far:

set_error_handler("myErrorHandler");
/**
 *My function to handle errors
 */
function myErrorHandler( $errno , $errstr ,  $errfile="nofile" , $errline=0 , $errcontextArray=NULL ){
    session_start();
    if (!isset($errno)|!isset($errstr)) {
        exit(0);
    }
    if (!mysql_ping()) {
        require '../Connection/databaseinfo.php';
    }
    $id_user = $_SESSION['ident'];
    $errstr = GetSQLValueString($errstr, "text");
    $errfile = GetSQLValueString($errfile, "text");
    $errline = GetSQLValueString($errline, "int");
    $sql = "insert into error_history 
        (id_user, message, file, line)
        values ($id_user, $errstr, $errfile, $errline)";
    mysql_query($sql) or die (mysql_error());

//    header("location:error.php"); ---> I can't (see comment below)
    echo "<script type='text/javascript'> window.location.href='error.php';</script>";//Redirection dégueulasse //TODO: trouver mieux
    return true;
}

Why not header()? Because the error can be triggered anywhere in a page, and thus, having the headers already sent.

Why not header() along with obstart(), ob_flush()? Because there are lot of pages already in production, and I can’t modify them all.

My questions are:

  1. Am I doing it wrong?
  2. Is there a better way to handle the
    redirection?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:49:33+00:00Added an answer on June 6, 2026 at 6:49 pm

    This is how to handle fatal errors in php 5.2:

    <?php
    register_shutdown_function('shutdownFunction');
    function shutDownFunction() {
        $error = error_get_last();
        if($error['type'] >= 1){
            mail('cc@cc.de', 'Error: XY',"Error msg:"."Server Error:".implode("\n", $error));
        }
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently maintaining a legacy Visual Basic project that has these procErr: statements all
I'm maintaining a project that was not initially using a version control system. Instead,
I work for an agency that has been responsible for maintaining a client’s .net
I have an ASP.NET site that I am maintaining. Currently it has code that
We have an autotools project that has a mixture of unit and integration tests,
I'm hoping that someone has some workflow tips on tracking separate but very (90%)
In a project that I am maintaining, I found a java class with a
I have a very large codebase (read: thousands of modules) that has code shared
We're inherting a project at work from another office that has closed down. The
I am maintaining a VS2010 project which has a number of cross-referenced COM libraries.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.