如何在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