Lately I have been writing function after function that gets my server name
www.example.com from an .ini file which I created... then I find this: $SERVER['SERVERNAME']. Is there anything wrong with using $SERVER['SERVERNAME'] in production? Any caveats, any pitfalls, any dangers?
Thanks in advance,
Why not just setup a constant in your php --
I've seen some debate on $SERVER['SERVERNAME'] and $SERVER['HTTPHOST'], which require Apache to have your VHost canonical name setup, otherwise you'll get the wrong data. But I know very little about it, I've used the $_SERVER variable once or twice, not much, and can't recall having any problems with it.
Cron jobs often execute a PHP script directly (i.e. without the webserver being used) so the $_SERVER variable won't exist.
Also worth noting that SERVER_NAME will return your domain name, if on a live server, or localhost, if that's what's in your address bar. Or, if you call the site via an ip address eg 127.0.0.1 instead of localhost, then it'll return the ip address. You might have already considered this, but it catches some people out.