What are the potential risks of hardcoding file paths in PHP scripts and how can they be mitigated?

Hardcoding file paths in PHP scripts can lead to issues when moving the script to a different server or directory. To mitigate this risk, it's best to use relative paths or define a base path variable that can be easily updated if needed.

// Define base path variable
$basePath = '/path/to/your/directory/';

// Use the base path variable to construct file paths
include $basePath . 'file.php';