I’m writing code in PHP that requires including a config.php file depending on the website URL.
I’ve the website URL in the variable $site, and the config for $site is in the directory configs/$site/config.php.
How can I require this file dynamically in PHP?
Is it safe to do include "configs/$site/config.php";?
If you limit
$siteto a set of values, yes.But remember: Never trust anything from outside, always validate values, that come from a client (browser).