PHP Hiding Error Path

  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

When I get a PHP error like:

Warning: Illegal offset type in \file\path\here\file.php on line 273

Is it possible to still E_ALL errors, but hide the path "\file\path\here\file.php"?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

http://www.php.net/set-error-handler

PHP Code: [ Select ]
<?php
 
function depath($errno, $errstr, $errfile, $errline)
 
{
 
   echo $errstr . preg_replace('#.+[\\/]([^\\/]+)$#i', '<br/>$1', $errfile) . ' Line ' . $errline;
 
   return true;
 
}
 
set_error_handler('depath');
 
echo "no$no";
 
?>
  1. <?php
  2.  
  3. function depath($errno, $errstr, $errfile, $errline)
  4.  
  5. {
  6.  
  7.    echo $errstr . preg_replace('#.+[\\/]([^\\/]+)$#i', '<br/>$1', $errfile) . ' Line ' . $errline;
  8.  
  9.    return true;
  10.  
  11. }
  12.  
  13. set_error_handler('depath');
  14.  
  15. echo "no$no";
  16.  
  17. ?>
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

joebert wrote:
http://www.php.net/set-error-handler

PHP Code: [ Select ]
<?php
function depath($errno, $errstr, $errfile, $errline)
{
   echo $errstr . preg_replace('#.+[\\/]([^\\/]+)$#i', '<br/>$1', $errfile) . ' Line ' . $errline;
   return true;
}
set_error_handler('depath');
echo "no$no";
?>
  1. <?php
  2. function depath($errno, $errstr, $errfile, $errline)
  3. {
  4.    echo $errstr . preg_replace('#.+[\\/]([^\\/]+)$#i', '<br/>$1', $errfile) . ' Line ' . $errline;
  5.    return true;
  6. }
  7. set_error_handler('depath');
  8. echo "no$no";
  9. ?>


Awesome man thx, totally forgot about error handling, never really did it. However, can't you just use basename() instead of preg_replace()? preg_replace() wouldn't work on windows because of the backslash in the path. Will it mess something up if I use basename()? Seems to work.
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

1 more thing... I pretty much setup all my error reporting and it works awesome.

There is just one problem though (well 2-in-1). I "echo" the errors I get in my error handler function and whenever I get a warning or notice error, instead of my site still loading, it sends the "header output already started" errors and then just kills the script.

So when I get a warning it kills the entire script, but when I used to get a warning it would just put it above my HTML and run the rest of the script.

Also another thing, when it shows the header error messages it still shows the full path, which kind of defeats the purpose. :cry:
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

*bump*

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: VanessaGilbert and 141 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.