What best practices should be followed when dealing with file paths and includes in PHP scripts?
When dealing with file paths and includes in PHP scripts, it is important to use absolute paths instead of relative paths to ensure that the correct files are included regardless of the current working directory. Additionally, using constants to define base paths can make it easier to manage file paths across different scripts. Finally, always sanitize user input to prevent directory traversal attacks.
<?php
define('BASE_PATH', realpath(dirname(__FILE__)));
// Include file using absolute path
include BASE_PATH . '/includes/config.php';