How can error_reporting and htaccess be used to troubleshoot and secure PHP code?

To troubleshoot PHP code, you can use the error_reporting function to display or log errors. By setting the error_reporting level to E_ALL, you can catch all errors and warnings, helping you identify and fix issues in your code. Additionally, using htaccess files, you can secure your PHP code by restricting access to certain directories, setting custom error pages, or disabling directory browsing.

// Enable error reporting to display or log errors
error_reporting(E_ALL);

// Example htaccess code to secure PHP code
// Disable directory browsing
Options -Indexes

// Set custom error pages
ErrorDocument 404 /errors/not_found.html

// Restrict access to a specific directory
<Directory "/path/to/directory">
  Order deny,allow
  Deny from all
</Directory>