更新时间:2023-02-23 22:11:38
看看$_SERVER['REQUEST_URI']
,即
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
(注意双引号字符串语法是完全正确)
(Note that the double quoted string syntax is perfectly correct)
如果你想同时支持 HTTP 和 HTTPS,你可以使用
If you want to support both HTTP and HTTPS, you can use
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
编者注:使用此代码具有安全隐患.客户端可以将 HTTP_HOST 和 REQUEST_URI 设置为它想要的任意值.
Editor's note: using this code has security implications. The client can set HTTP_HOST and REQUEST_URI to any arbitrary value it wants.