Can I hide the path in php error using .htaccess

坚强是说给别人听的谎言 提交于 2019-12-25 03:43:30

问题


Can I hide the path in php error using .htaccess

Example:

Notice: Undefined variable: hello in C:\xampp\htdocs\mysite\index.php on line 3

I want to hide the path using .htaccess or print something let me know if there is an error without print the path of the page:

Notice: Undefined variable: hello on line 3

or

Notice: Undefined variable: hello

or

There is error in your page

Edit :

I put this lines in my .htaccess But I can't access to my site. There is error "Internal Server Error" How Can I fix that

# supress php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0

回答1:


PHP’s error messages are not meant for users but for developers only.

So for a production environment, you should disable display_errors to avoid information disclosure:

Note: [display_errors] is a feature to support your development and should never be used on production systems (e.g. systems connected to the internet).

Instead, you should show generic error messages to your users that do not unveil anything of the internals and only log the error messages (see log_errors and error_log):

Note: You're strongly advised to use error logging in place of error displaying on production web sites.

And if you really want to modify PHP’s error messages, you can use set_error_handler to set a custom error handler.

See also OWASP’s Development Guide on “Error Handling, Auditing and Logging” for further information.




回答2:


You cannot change the messages : those are generated by PHP, and that's the way they are.


But you can prevent them from being displayed to your website's users -- and still log them, for your own usage.
For that, see :

  • display_errors : to prevent errors from being displayed to the page's output
  • log_errors : to indicate that errors should be logged to a file
  • error_log : to specify to which file errors will be logged to.


Of course, that doesn't prevent you from fixing as many causes of notices / warnings / errors as possible ;-)




回答3:


Get rid of all that useless stuff.

php_flag display_errors 0

alone will be enough.

If error persists, check server's error_log for the error message



来源:https://stackoverflow.com/questions/5605512/can-i-hide-the-path-in-php-error-using-htaccess

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!