PHP implements code for home page link query and friendly link check

PHP中文网
Release: 2019-01-30 13:20:14
Original
2097 people have browsed it



Copy code The code is as follows:

<?php 
/* 
* 网站首页超链接反查 友情链接查询 外链查询 
* web技术爱好者 lost63.com原创 QQ:35501547 
* 转载请注明出处 
*/ 
if($_GET[&#39;action&#39;]=="check"){ 
$domain=$_POST[&#39;domain&#39;]; 
//域名表单项为空,则获取地址栏参数 
if($domain==""){ 
$domain=$_GET[&#39;domain&#39;]; 
} 
//网址 
$url="http://".$domain; 
//读取网页,返回网页源文件内容 
function read_url($str){ 
$file=fopen($str,"r") or die($str.&#39;->远程网址读取失败! <a href="?next=&#39;.($_GET[&#39;next&#39;]+1).&#39;&action=check&domain=&#39;.$_GET[&#39;domain&#39;].&#39;">点击继续查询</a><br>&#39;); 
while(!feof($file)){ 
$result.=fgets($file,9999); 
} 
fclose($file); 
return $result; 
} 
//打开session 
session_start(); 
//如果$_SESSION[&#39;matches&#39;]没有赋值就设置它; 
if(!isset($_SESSION[&#39;matches&#39;])){ 
$result=read_url($url); 
preg_match_all(&#39;/<a(.*?)href="(http:\/\/.*?)"(.*?)>(.*?)<\/a>/i&#39;,$result,$matches); 
$num=count($matches[2]); 
for($i=0;$i<$num;$i++){ 
if(strpos($matches[2][$i],$domain)>0){ 
unset($matches[2][$i]); 
} 
} 
$_SESSION[&#39;matches&#39;]=$matches[2]; 
} 
//直接从session中取出包含网址数组; 
$matches[2]=$_SESSION[&#39;matches&#39;]; 
$n=count($matches[2]); 
$next=0; 
$next+=$_GET[&#39;next&#39;]; 
$result=read_url($matches[2][$next]); 
if(strpos($result,$domain)>0){ 
$value=$matches[2][$next].&#39; <font color=green>true</font><br>&#39;; 
}else{ 
$value=$matches[2][$next].&#39; <font color=red>false</font><br>&#39;; 
} 
$values=$_COOKIE[&#39;check_result&#39;].$value; 
setcookie("check_result",$values,time()+3600); 
echo $values; 
if($next==$n){ 
echo "扫描结束!"; 
}else{ 
echo &#39;<meta http-equiv="refresh" content="1;URL=?next=&#39;.($next+1).&#39;&action=check&domain=&#39;.$domain.&#39;" />&#39;; 
} 
}else{ 
//删除cookies 
setcookie("check_result","",time()-3600); 
echo &#39;<form name="form1" method="post" action="?action=check"> 
<input type="text" name="domain"> 
<input type="submit" name="Submit" value="提交"> 
<font color="red">*</font>输入域名 如:jb51.net 
</form>&#39;; 
} 
?>
Copy after login



http://www.bkjia.com/PHPjc/321019.htmlwww.bkjia .comtruehttp://www.bkjia.com/PHPjc/321019.htmlTechArticle Copy code The code is as follows: ?php /* *Reverse check of hyperlinks on the homepage of the website, query of friendly links, query of external links*Original QQ by web technology enthusiast lost63.com:35501547 * Please indicate the source when reprinting*/ if($_G...



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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template