I try to execute a bat, and in this file i try to acceed to this variable :
$_SERVER['SERVER_NAME']
But it doesn’t exist this index. In fact, when i try to print_r($_SERVER), there is no SERVER_NAME index. There is a reason ? Is it because i launch this function in a bat ?
Have I an other solution for get this variable ?
Thank you !
The
$_SERVERvariables are only available in a server environment (hosting PHP through Apache or another web server), so if you are launching it from the command line they won’t be available. The parameters of this object are populated by the HTTP headers, which in your case don’t exist.If you want to ignore the
$_SERVERobject when theSERVER_NAMEisn’t set, you can alternative usephp_uname("n")but your mileage may vary depending on operating system.