hypernetware — 2010-12-13T21:06:05-05:00 — #1
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,
jream — 2010-12-13T23:02:16-05:00 — #2
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.
cranial_bore — 2010-12-14T02:25:48-05:00 — #3
Cron jobs often execute a PHP script directly (i.e. without the webserver being used) so the $_SERVER variable won't exist.
hessodreamy — 2010-12-14T04:47:22-05:00 — #4
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.