Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中获取主机名?_Php - Fatal编程技术网

如何在PHP中获取主机名?

如何在PHP中获取主机名?,php,Php,这就是我尝试过的: header('location: http://".$_SERVER["HTTP_HOST"]."/HTML-CW/Account.html'); 我也试过这个 $hostDb = $_SERVER["HTTP_HOST"]; header('location: http://"$hostDb"/HTML-CW/Account.html'); 获取主机名 服务器名称由服务器配置决定; HTTP_主机与请求绑定 标题('location:http://'.$\u SERV

这就是我尝试过的:

header('location: http://".$_SERVER["HTTP_HOST"]."/HTML-CW/Account.html');
我也试过这个

$hostDb = $_SERVER["HTTP_HOST"];
header('location: http://"$hostDb"/HTML-CW/Account.html');

获取主机名

服务器名称由服务器配置决定; HTTP_主机与请求绑定

标题('location:http://'.$\u SERVER[“http_HOST”]./HTML-CW/Account.HTML')

标题('location:http://'.$\u SERVER[“SERVER\u NAME”]./HTML-CW/Account.HTML')

这会解决你的问题。请参阅“转换为”


还可以执行echo($\u SERVER[“SERVER\u NAME”])和echo($\u SERVER[“HTTP\u HOST”])来查看它在您的环境中输出的内容。

尝试
标题('location:HTTP://')。$\u SERVER[“HTTP\u HOST”]./HTML-CW/Account.HTML');
。请注意使用单引号而不是双引号。您可以使用任意一个引号,但在语句中要一致。重复:这是否回答了您的问题?
$_SERVER['SERVER_NAME'] Returns the name of the host server (such as www.google.com)

$_SERVER['HTTP_HOST'] Returns the Host header from the current request

http://www.google.com
HTTP_HOST = www.google.com
SERVER_NAME = google.com

http://172.217.31.206
HTTP_HOST = 172.217.31.206
SERVER_NAME = google.com