PHP Hiding Error Path

  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Feb 17, 2005
  • Posts: 1585
  • Status: Offline

Post December 6th, 2007, 7:37 pm

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
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post December 6th, 2007, 7:37 pm

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post December 6th, 2007, 10:53 pm

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. ?>
Strong with this one, the sudo is.
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Feb 17, 2005
  • Posts: 1585
  • Status: Offline

Post December 7th, 2007, 11:26 am

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
  • Joined: Feb 17, 2005
  • Posts: 1585
  • Status: Offline

Post December 7th, 2007, 12:12 pm

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
  • Joined: Feb 17, 2005
  • Posts: 1585
  • Status: Offline

Post December 12th, 2007, 3:44 pm

*bump*

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 218 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.