Is $_SERVER['SERVER_ADDR'] always set?
Should I check with isset() or is that unnecessary?
I need to get the IP of the site so I can find out if it’s 127.0.0.1/localhost
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s not going to always be set. Consider that you can install PHP without even having a server and run it from command line. There is no guarantee with any of the
$_SERVERvariables, but if you try it once on your server and it works then you can bet that it will always be set on that server configuration. You just need to make a note somewhere that if you ever do a major change on your server’s configuration, or switch servers you should check it again.You can also check the value of your server variables with
phpinfo()