Question

Stop PHP errors revealing path

Asked by: sciwriter

Now I'm back to using PHP, I realize one of this greatest annoyances that stopped me using it years ago.

Whenever it generates an error, it reveals to the user the ENTIRE PATH to gain access to your account.

This has got to be one of the STUPIDEST, DUMBEST oversigns of the century.

I need a GLOBAL FIX, which will ELIMINATE SHOWING THE PATH ON THE SERVER.

If I cannot get this, I cannot use PHP -- that was my conclusion years ago.

Anyone know how to STOP the PATH portion of the typical PHP error message --

"PHP error in **'my_root/my_account_name/here_hackers/come_hack_my_server/steal_my_account'**"

Talk about DUMB, DUMB, DUMB -- stupider than dumb !!!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-03-26 at 23:29:51ID21365917
Tags

error_reporting

Topic

PHP Scripting Language

Participating Experts
4
Points
250
Comments
27

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. not to reveal our ip
    Hi, Can any one suggest me any software that won't reveal my system ip if I was in internet and accessing the websites.
  2. sendmail reveals webhost and servername (using mail()…
    php 4.4.2 mail() working fine BUT if you look at full headers in the email you can see name of webhost AND the name of server the site is hosted on. (in Return-path, Received: from, and Message-Id) any way to fix? (I am not a spammer. just dont want to reveal any more info...
  3. Reveal Formatting
    I'm setting up a laptop someone else used and they had used English/Arabic... I have it all set for english and even reinstalled Office but every time I open word at the botton is says Arabic but as soon as I typ something it types it in english which is fine but it is typing...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: gruntarPosted on 2005-03-26 at 23:35:34ID: 13638613

You cannot hide only path. When you publish your page add line below to a file that is included at the beggining of all other files.

error_reporting(0);

that will block all kinds of errors except the ones you call with die()...

cheers

 

by: sciwriterPosted on 2005-03-26 at 23:41:19ID: 13638624

I was hoping to block the PATH ONLY, not the error itself, since they help debug.  Are you sure there is no way to substitute something for the path, or eliminate it?  So to stop the path showing, I have to issue no die() statments, and I cannot even use something like a 404 redirect???  What an incredible oversight !!!

 

by: gruntarPosted on 2005-03-27 at 00:17:12ID: 13638671

No, I just said that for production server you hide errors for obvious reasons. I didn't say that because there are some errors that cannot be predicted so you cannot know where to put or die()

For advanced error reporting see "Error Handling and Logging Functions" that way you have ability to do whatever you want with errors... http://www.php.net/manual/en/ref.errorfunc.php

Why would you debug on production server? You should test/debug your application on local server.

cheers

 

by: matt_mcswainPosted on 2005-03-27 at 01:32:09ID: 13638764

>>This has got to be one of the STUPIDEST, DUMBEST oversigns of the century.

Don't think so; this is somewhat important information for debugging purposes.
What if your application uses 50 other files?
If there's an error, I want to know exactly where it is. I wish errors gave even more detail. :)
To echo what gruntar said, common practice is to turn error reporting off on live environments and just log the errors.
Do you think php is the only web language that does this?

However if you really want to stop this, you can look at set_error_handler()-->http://us2.php.net/set_error_handler
There's a nice example on the page. Basically you create your own function that will handle errors that are encountered, but some errors can not be handled by it(i.e. parse errors); but many can.
Also, one of the parameters sent to your error handler is of course 'filename'. So instead of echoing the whole filename, you could use:

basename($errfile)

which will only show the file, and none of the path.

 

by: sint4xPosted on 2005-03-27 at 09:48:55ID: 13639894

>> If there's an error, I want to know exactly where it is. I wish errors gave even more detail. :)

IMO hiding directories are important, security reasons.

 

by: sciwriterPosted on 2005-03-27 at 10:58:53ID: 13640165

Thought it would be obvious here I was talking about final production running -- NOT the initial debuging stages.  Two different worlds.  Sint4x, so glad you see this too.

Evidently I wasnt' clear enough.  I KNOW where my files are, I KNOW exactly what the path is -- I don't need this echoed back to me or advertised to the rest of the world -- THAT is what is dumb.  I don't see anything in the two links to just turn off the path.  

Perhaps someone would like to just provide a simple statement that turns off the path on ALL errors on a server.  That is what I need.  The PATH, not the errors.  

 

by: gruntarPosted on 2005-03-27 at 11:43:36ID: 13640304

>>  I KNOW where my files are, I KNOW exactly what the path is -- I don't need this

Yes, you do an don't know. Here is example...

test.php

<?php
include('file1.php');
include('file2.php');
include('file3.php');

//some more code here
?>

if you run "test.php" you also run all included files. Now, let say that for some reasons some error occur in included file "file2.php".

Now, if PHP wouldn't reveal the file where error occur You would not have a clue in which file you have a bug. This is the reason why you get all that info PHP gives you. I hope it's a bit clearer now.

cheers

 

by: gruntarPosted on 2005-03-27 at 12:05:22ID: 13640373

here is your error reporting that don't reveal server path..

test.php
<?php

//error_reporting(E_ALL);
error_reporting(0);


function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
{

   $errortype = array (
               E_ERROR          => "Error",
               E_WARNING        => "Warning",
               E_PARSE          => "Parsing Error",
               E_NOTICE          => "Notice",
               E_CORE_ERROR      => "Core Error",
               E_CORE_WARNING    => "Core Warning",
               E_COMPILE_ERROR  => "Compile Error",
               E_COMPILE_WARNING => "Compile Warning",
               E_USER_ERROR      => "User Error",
               E_USER_WARNING    => "User Warning",
               E_USER_NOTICE    => "User Notice",
               E_STRICT          => "Runtime Notice"
               );
   // set of errors for which a var trace will be saved
   $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
   
   $err = '<br />';
   $err .= ' <b>' . $errortype[$errno] . '</b>';
   $err .= ' ' . $errmsg;
   $err .= ' <b>' . basename($filename) . '</b>';
   $err .= ' ' . $linenum;

   
   // echo error without paths..
    echo $err;

}

set_error_handler('userErrorHandler');



echo $dsf

?>

few lines above I have "forgot" to add traling ; so error should like ...

Notice Undefined variable: dsf test.php 45

cheers

 

by: sciwriterPosted on 2005-03-27 at 12:05:52ID: 13640374

Thank you gruntar for all the explanations you have put in -- I DO understand why some PHP coders think you need to display the file path -- but I don't want that information to show at all -- once in production.

Perhaps someone would like to just provide a simple GLOBAL statement that turns off the path on ALL PHP errors on a server.  That is what I need.  The PATH turned off, not the errors.

If that is impossible, then I would settle for -- ALL errors supressed -- everything.
I cannot live with intermittent PHP and MySQL errors revealing the path to the account on the server.  
Repeat, I cannot live with it -- once in production.  

Thanks for a brief, working solution  -- hopefully juat a 1-2-line statement.

 

by: sciwriterPosted on 2005-03-27 at 12:09:36ID: 13640382

Sorry gruntar -- I posted before I saw your code  -- Thank you for that code....

Does this code go in each page, or can I put it somewhere more "globally"?

An include, or can I specify it in something like the htaccess?  

 

by: matt_mcswainPosted on 2005-03-27 at 12:12:45ID: 13640393

>>IMO hiding directories are important, security reasons.
I'm not disagreeing. I'm just saying turn them off and log them on live servers.
Yes, I suppose, it would be nice it there was an error flag that would prevent the path from being displayed.
I guess they think we have enough options.

 

by: gruntarPosted on 2005-03-27 at 12:13:07ID: 13640395

You can put it in a file that gets included in every file. this code should be first one to execute.

cheers

 

by: sciwriterPosted on 2005-03-27 at 12:46:14ID: 13640525

OK, I  put all your code in a file called errors.php  uploaded it to the server,
Changed the file giving errors to add, at top --     <?php include("errors.php"); ?>
All the errors still show, and I am also getting this additional error --

" Notice Undefined variable: dsf errors.php 50 "

I put the ; after dsf, but notice, it is not defined above.
Also, since this is a function, do I have to call it in every single php action
if ... else die(errors.php)  -- or something like that?

That would be too much hassle.  I assumed it can replace the standard error handling.
Also, all the warnings on the page are showing the path as well....

 

by: sint4xPosted on 2005-03-27 at 13:36:53ID: 13640642

gruntar you saved my life!

I always was looking for a way to debug my production server errors!! Now I have complete control over them :)

THank you.

 

by: sciwriterPosted on 2005-03-27 at 13:42:09ID: 13640651

Then please fill me in on getting this working -- as it is not working for errors for me, or for warnings.  Please see my post above...

 

by: gruntarPosted on 2005-03-27 at 13:59:39ID: 13640688

you must put this code into that file


<?php

error_reporting(0);


function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
{

   $errortype = array (
               E_ERROR          => "Error",
               E_WARNING        => "Warning",
               E_PARSE          => "Parsing Error",
               E_NOTICE          => "Notice",
               E_CORE_ERROR      => "Core Error",
               E_CORE_WARNING    => "Core Warning",
               E_COMPILE_ERROR  => "Compile Error",
               E_COMPILE_WARNING => "Compile Warning",
               E_USER_ERROR      => "User Error",
               E_USER_WARNING    => "User Warning",
               E_USER_NOTICE    => "User Notice",
               E_STRICT          => "Runtime Notice"
               );
   // set of errors for which a var trace will be saved
   $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
   
   $err = '<br />';
   $err .= ' <b>' . $errortype[$errno] . '</b>';
   $err .= ' ' . $errmsg;
   $err .= ' <b>' . basename($filename) . '</b>';
   $err .= ' ' . $linenum;

   
   // echo error without paths..
    echo $err;

}

set_error_handler('userErrorHandler');

?>

 

by: gruntarPosted on 2005-03-27 at 14:00:34ID: 13640690

No problem sint4x, glad I could help :)

 

by: sciwriterPosted on 2005-03-27 at 14:22:08ID: 13640731

gruntar --

I have put your new code into a file called -- errors.php -- in the <BODY> section.

In the top of filename.php  I have put --
<?php
include("errors.php");
.......
?>

I am still getting tons of warnings and errors, like --

Warning session_start(): Cannot send session cookie - headers already sent by (output started at /home/path/public_html/filename.php:7) filename.php 44
Warning session_start(): Cannot send session cache limiter - headers already sent (output started at /home/path/public_html/filename.php:7) filename.php 44
Warning Cannot modify header information - headers already sent by (output started at /home/path/public_html/filename:7) filename.php 45
Warning end(): Passed variable is not an array or object filename.php 55

Don't worry about the meanings of the errors -- I just want to eliminate them....
Obviously I am not doing something right

 

by: gruntarPosted on 2005-03-27 at 14:31:45ID: 13640766

What BODY?!

Put only PHP code that I have posted in last post NOTHING else!!!

cheers

 

by: sciwriterPosted on 2005-03-27 at 14:42:20ID: 13640784

I did that, it made no difference.

As I said, your file declares a function -- where do I call this function?
I am not calling any function -- only:    include "errors.php"   -- in the other file.

Seems to me a function has to be called, unless this replaces PHP's global error reporting.

I am increasing points for all the effort you have put in, but it is still not working.
Something simple, no doubt.

 

by: gruntarPosted on 2005-03-27 at 14:48:29ID: 13640813

Well, yes you DON'T call that function, PHP does.

set_error_handler('userErrorHandler');
this line tells PHP to use your function to show errors.

Have you copyed whole code?

 

by: sciwriterPosted on 2005-03-27 at 15:08:09ID: 13640846

yes gruntar, exactly as you have it.  Since I am not a PHP expert, it is probably something real simple.  I don't doubt the correctness of your code, I would suspect I am missing something that might be "obvious" to you...

In the other file, I tried --

include("errors.php");

with and without the brackets, made no difference.  I even copied your latest code again, and re-upoaded that errors.php to the public_html directory.  There is nothing in it but your code.

server stats --

Apache version  1.3.33 (Unix)        
MySQL version      4.0.22-standard      
PHP version      4.3.10

Sorry for the problem, but I really need to get these errors out of the way, so I can see what I am doing ....

 

by: gruntarPosted on 2005-03-27 at 15:15:21ID: 13640856

Based on info you have posted seems OK. I can tell you more only if you paste the code...

 

by: sciwriterPosted on 2005-03-27 at 15:30:31ID: 13640889

errors.php is EXACTLY your code -- checked it 3 times

otherfile.php is as follows (simplified, to not clutter this question) --

<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META http-equiv="Content-Style-Type" content="text/css">
<TITLE></TITLE>
</HEAD>
<BODY>
....some HTML tables here

<?php

include ("errors.php") ;

session_start();
header("Cache-control: private");                                     // IE 6 Fix.
if (!session_is_registered('divs')) { session_register('divs'); }

// there is a whole bunch more code relating to displaying session information, none relevant to the errors
//because the errors relate to the above code, but they are typical PHP errors (see above). Example code --
  echo "<DIV id='" . $key . "'>Description: ". $_SESSION['divs'][$key]['title'] . "</DIV>";

?>

.... more HTML tables here

</BODY>
</HTML>

 

by: gruntarPosted on 2005-03-27 at 15:38:29ID: 13640912

Code should go like this.
Headers must be sent before any output...


<?php

include ("errors.php") ;

session_start();
header("Cache-control: private");                               // IE 6 Fix.
if (!session_is_registered('divs')) { session_register('divs'); }

?><HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META http-equiv="Content-Style-Type" content="text/css">
<TITLE></TITLE>
</HEAD>
<BODY>


If you have problems TRY simple test files first and then add more code to it...
now, i'm off to bed.. its 1:38 here

 

by: SquinkyPosted on 2005-03-29 at 01:29:05ID: 13650770

There's a simpler approach to this. Either set display_errors = off in your php.ini, or say this at the start of each script:

ini_set('display_errors', 0);

It's important to not turn error_reporting off as it will stop you seeing real errors in your log files, but turning their display off will stop making them public. Of course, errors like these should not happening anyway, so you should be more careful with your error checking to stop them occurring in the first place - but I'm sure you know that!

 

by: sciwriterPosted on 2005-03-29 at 10:55:28ID: 13655145

Thank you squinky, that simple statement is what I was looking for all along !!!

I was using error reporting(0) to stop them, so I could move ahead with debugging, and I will change that to your suggestion.

Since yours is the right answer -- but gruntar put in so much effort with his code (that I still could not get to work) -- If it is OK with you both, I will split points evenly.

Thanks again squinky -- check my other posts, could use your help.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...