Home  >  Article  >  php教程  >  PHP取得访问者的域名实例代码

PHP取得访问者的域名实例代码

WBOY
WBOYOriginal
2016-06-21 08:57:221559browse

取得IE地址栏的访问者域名.

$S = 'http://bbs.webjx.com';
$S = parse_url($S);
$S = strtolower($S['host']) ; //取域名部分
//echo $S;

$domain = array('com','cn','name','org','net'); //域名后缀 有新的就扩展这吧
$SS = $S;
$dd = implode('|',$domain);
$SS = preg_replace('/(\.('.$dd.'))*\.('.$dd.')$/iU','',$SS); 把后面的域名后缀部分去掉
 
$SS = explode('.',$SS);
$SS = array_pop($SS);  //取最后的主域名
$SS = substr($S,strrpos($S,$SS));  //加上后缀拼成完成的主域名
echo $SS;
?>



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn