Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-21 08:57:22
Original
1535 people have browsed it

取得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;
?>



Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!