SERVER_ADDR error in PHP

Asked

Viewed 40 times

0

Does anyone know any solution to this mistake

Notice: Undefined index: SERVER_ADDR in C:\certificado\config.php on line 10

The line he refers to is :

$desenvIp = ($_SERVER["SERVER_ADDR"] == "::1") ? "::1" : "127.0.0.1";

I am using PHP 7

  • In accordance with official documentation: "There is no guarantee that each web server will provide any of these; servers may omit some". Why do you need that amount?

  • I use in two cases if, to perform the configuration of the system root folder, by explemo: if ($_SERVER["SERVER_ADDR"] == $desenvIp)

 $files['rootSys'] = "/certificado/";
else if ($_SERVER["SERVER_ADDR"] == $webIp)

 $files['rootSys'] = "/certificado/";

  • So basically you just use it to identify the environment, so why not use an environment variable?

  • I understand, but for example, I have to define a URL to differentiate the production urls from the development ones. Following : if ($_SERVER['SERVER_ADDR'] == $webIp) {
 define("URL_SISTEMA", $url['producao']);
 define("URL_SITE", $url['producao_site']);
 define("URL_SITE_TPL", $url['producao_site_template']);
}
else {
 define("URL_SISTEMA", $url['desenvolvimento']);
 define("URL_SITE", $url['desenvolvimento_site']);
 define("URL_SITE_TPL", $url['desenvolvimento_site']);
} Where this webIP is the ip of the production machine, how to do with environment variables ?

  • How would it be possible to make this comparison with an ambient variable, to make this comparison ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.