我是php的新手。这是我的代码:
$domain = $_SERVER['HTTP_HOST'];
$uri = parse_url($_SERVER['HTTP_HOST']);
$r_domain = substr(['host'], strpos($uri['host'],"."), strlen($uri['host']));
if ( $domain == $r_domain ) {
/*Open the connection to our database use the info from the config file.*/
$link = f_sqlConnect('root', '', 'group_project');
答案 0 :(得分:1)
parse_url
旨在以这种形式解析字符串:
scheme://host/path?query#fragment
所以,如果你解析这个字符串:
https://www.example.com/pages/mypage.php?one=two#wow
parse_url
的结果将是:
Array
(
[scheme] => https
[host] => www.example.com
[path] => /pages/mypage.php
[query] => one=two
[fragment] => wow
)
但你解析$_SERVER['HTTP_HOST']
,就像'localhost','www.mysite.com','127.0.0.1'。换句话说,一个字符串对parse_url
没有特别的意义,因为没有任何元素可以将它与URL相关联。
解析(即)'localhost'将仅获得此:
Array
(
[path] => localhost
)