What are the potential pitfalls of using $_SERVER['SERVER_NAME'] to determine domain?
Using $_SERVER['SERVER_NAME'] to determine the domain can be unreliable as it relies on the server configuration, which may not always be accurate. It is better to use a combination of other server variables like $_SERVER['HTTP_HOST'] and $_SERVER['SERVER_PORT'] to determine the domain more accurately.
$domain = $_SERVER['HTTP_HOST'] . ($_SERVER['SERVER_PORT'] != 80 ? ':' . $_SERVER['SERVER_PORT'] : '');
Related questions
-
PHP special characters string manipulation
-
file permissions file locking file system errors
-
clean URLs PHP applications search engine optimization