Heim  >  Artikel  >  Backend-Entwicklung  >  php实现首页链接查询 友情链接检查的代码

php实现首页链接查询 友情链接检查的代码

PHP中文网
PHP中文网Original
2016-07-21 15:42:022049Durchsuche



复制代码 代码如下:

<?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;; 
} 
?>



http://www.bkjia.com/PHPjc/321019.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321019.htmlTechArticle复制代码 代码如下: ?php /* * 网站首页超链接反查 友情链接查询 外链查询 * web技术爱好者 lost63.com原创 QQ:35501547 * 转载请注明出处 */ if($_G...



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn