php获取请求完整的url_如何在PHP中获取完整的请求URL?

php获取请求完整的url

How to get the full request URL of the page being processed in PHP?

如何获取正在PHP中处理的页面的完整请求URL?

If you are sure the request is a http or https one, and the PHP script is executed according to (e.g. by a load balancer or apache reverse proxy) the REQUEST_URI/HTTP_HOST which are set by the client, the PHP script can get the actual URL by

如果您确定请求是http或https ,并且PHP 脚本是根据(例如,由负载平衡器或apache反向代理执行 )由客户端设置的REQUEST_URI / HTTP_HOST执行的,则PHP脚本可以获得实际的网址由

$url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

If it is necessary, escape the $url such as:

如有必要,请转义$url例如:

$url = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');

Answered by Eric Z Ma. 埃里克·马(Eric Z Ma)回答。

翻译自: https://www.systutorials.com/how-to-get-the-full-request-url-in-php/

php获取请求完整的url

    原文作者:cuma2369
    原文地址: https://blog.csdn.net/cuma2369/article/details/107666601
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞