php - Php get website url after https:// or www. or subdomain
问题描述
I want to get the correct URL with PHP without any error, my links example:
https://example.com/
https://example.com/search/
https://example.com/search/?q=test
https://it.example.com/
https://it.example.com/search/
https://it.example.com/search/?q=test
so i want to get all link if is https://example.com/ show example.com
if is https://example.com/search/ show example.com/search/
if is https://it.example.com/search/?q=test show example.com/search/?q=test
etc.. without any error. thanks
解决方案
看起来你需要$_SERVER['REQUEST_URI']
:
$link = "$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
也可以查看 PHP 文档: http: //php.net/manual/en/reserved.variables.server.php
这将返回没有 https 的 HTTP 主机,并且还会为您提供带有查询字符串等的 request_uri。
parse_url()
还将为您提供每个元素,然后您可以构建所需的字符串:
推荐阅读
- javascript - 由 jQuery 添加的什么都不发送
- php - 从 PHP 返回 True/False 到 Ajax
- python - 如何清除 EnvironmentError: [WinError 87] during "pip install qiskit"
- google-cloud-datastore - 谷歌云数据存储 GQL - 获取当前日期时间
- cpu-cache - 高速缓存内存以及它是如何填充的?
- lit-element - 当 Attribute 设置为 false 时,该属性是否仍可在元素内观察到?
- scikit-learn - ValueError:使用线性回归的垃圾邮件或非垃圾邮件预测
- asp.net-web-api - JSon 到 WebAPI 变为 [[]],[[]],[[]],[[]]
- angular - 使用ngrx在一个@Effect中构建多个HTTP调用的最简洁方法是什么
- oauth-2.0 - Google Home 帐号关联(返回结果时出错。)