站內搜尋

Thursday, June 2, 2016

[PHP] 如何抓到完整網址(FQDN)

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

詳細說明如下:
假設網址是: http://a.b.c:8080/d.php?e=123
$_SERVER['HTTP_HOST']: a.b.c:8080
$_SERVER['SERVER_NAME']: a.b.c
$_SERVER['REQUEST_URI']: /d.php?e=123
$_SERVER['PHP_SELF']: /d.php
$_SERVER['QUERY_STRING']: e=123

No comments:

Post a Comment