说我的URL地址是www.example.com
我希望在我的脚本中有一个if语句,如果url是www.example.com则测试条件为true,如果是其他内容则为false,例如www.example.com/test或www.example.com?var= 3功能= 7.
我该如何实现这一目标?它会增加网页加载的开销吗?正如我将在网站首页上发表这个if语句.
谢谢
它将添加无关紧要的加载时间,因为它只是解析一些头信息.
$_SERVER['HTTP_HOST'] // The host (e.g. www.example.com)
$_SERVER['REQUEST_URI'] // The URI (e.g. /something.php or /something.php?this=true)
Run Code Online (Sandbox Code Playgroud)
并实施:
if ($_SERVER['HTTP_HOST'] != "www.domain.com") // Do something
Run Code Online (Sandbox Code Playgroud)