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

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?php
/*
* 网站首页超链接反查 友情链接查询 外链查询
* web技术爱好者 lost63.com原创 QQ:35501547
* 转载请注明出处
*/

if($_GET['action']=="check"){

$domain=$_POST['domain'];

//域名表单项为空,则获取地址栏参数
if($domain==""){
$domain=$_GET['domain'];
}

//网址
$url="http://".$domain;

//读取网页,返回网页源文件内容
function read_url($str){

$file=fopen($str,"r") or die($str.'->远程网址读取失败! <a href="?next='.($_GET['next']+1).'&action=check&domain='.$_GET['domain'].'">点击继续查询</a><br>');
while(!feof($file)){
$result.=fgets($file,9999);
}
fclose($file);
return $result;

}

//打开session
session_start();

//如果$_SESSION['matches']没有赋值就设置它;
if(!isset($_SESSION['matches'])){
$result=read_url($url);

preg_match_all('/<a(.*?)href="(http:\/\/.*?)"(.*?)>(.*?)<\/a>/i',$result,$matches);
$num=count($matches[2]);
for($i=0;$i<$num;$i++){
if(strpos($matches[2][$i],$domain)>0){
unset($matches[2][$i]);
}
}

$_SESSION['matches']=$matches[2];
}
//直接从session中取出包含网址数组;
$matches[2]=$_SESSION['matches'];

$n=count($matches[2]);

$next=0;
$next+=$_GET['next'];

$result=read_url($matches[2][$next]);

if(strpos($result,$domain)>0){
$value=$matches[2][$next].' <font color=green>true</font><br>';
}else{
$value=$matches[2][$next].' <font color=red>false</font><br>';
}
$values=$_COOKIE['check_result'].$value;
setcookie("check_result",$values,time()+3600);
echo $values;

if($next==$n){
echo "扫描结束!";
}else{
echo '<meta http-equiv="refresh" content="1;URL=?next='.($next+1).'&action=check&domain='.$domain.'" />';
}


}else{
//删除cookies
setcookie("check_result","",time()-3600);
echo '<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>';
}
?>

相关文章

php基于curl实现随机ip地址抓取内容的方法

本文实例讲述了php基于curl实现随机ip地址抓取内容的方法。分享给大家供大家参考,具体如下: 使用php curl 我们可以模仿用户行为,既可以设置我们访问的ip及浏览器信息还可以设...

hadoop常见错误以及处理方法详解

1、hadoop-root-datanode-master.log 中有如下错误:ERROR org.apache.hadoop.hdfs.server.datanode.DataNod...

PHP多进程简单实例小结

本文实例讲述了PHP多进程。分享给大家供大家参考,具体如下: PHP创建多进程需要使用到pcntl模块 在编译时加上--enable-pcntl打开进程控制支持,不是Unix类系统不支持...

PHP整数取余返回负数的相关解决方法

PHP语言虽然功能强大,但并不代表其没有缺点,在编写代码的过程中未免会遇到一些让人头痛的问题。下面我们将为大家介绍有关PHP整数取余返回负数的解决办法。 我们先来看个例子. 复制代码 代...

php中注册器模式类用法实例分析

本文实例讲述了php中注册器模式类用法。分享给大家供大家参考,具体如下: 注册器读写类 Registry.class.php <?php /** * 注册器读写类...