Php | LsevenTT博客-站群哥
   

LsevenTT博客-站群哥

认真你就输了

PHP生成首页html静态文件

PHP生成首页html静态文件

 

PHP生成首页静态文件代码

分享一个 PHP生成静态首页index.html的代码

 

<?php
$baseCmsUrl = "http://www.LsevenTT.com";
//你网站的根目录不要加反斜杠/
$dmPageName = "index.php";
$stPageName = "index.html";
$tureStFile = dirname(__FILE__) . '/' . $stPageName;
$body = file_get_contents($baseCmsUrl . '/' . $dmPageName);
$fp = fopen($tureStFile, 'w');
fwrite($fp, $body);
fclose($fp);
header("Location:{$baseCmsUrl}/index.html");
//生成后返回静态首页
?>

 

 

 

根据user-agent判断蜘蛛跳转 (php版与js版本)

根据user-agent判断蜘蛛跳转 (php版与js版本)

黑帽seo手段中有一个大家都在用的技巧,在服务端判断 客户端浏览器的user-agent然后做进一步操作,

网上一直都有人在用 这个代码 先是一个js代码 判断网站访客来路 如果是搜索引擎来的 就跳转 如果是直接访问则不变化 这段代码是从网上找来的 已经很久了 不用感谢我

 

<script language="javascript">
var pattern = /baidu/gi;
var pattern1= /google/gi;
var keyValue=escape(document.referrer);
if (pattern.exec(keyValue))
setTimeout(
"windows.location='http://www.lseventt.com/%E7%AB%99%E7%BE%A4%E7%A8%8B%E5%BA%8F'",10*1000);
else if(pattern1.exec(keyValue))
setTimeout(
"window.location='http://www.lseventt.com'",10*1000);
</script>

判断搜索引擎进行不同的跳转

百度蜘蛛就会跳转到 http://www.lseventt.com/站群程序

判断是谷歌蜘蛛就会跳到 http://www.lseventt.com/

 

如果是搜索引擎的user-agent则301跳转

具体还有很多思路,跳转了,乔页等 今天仅把代码放出来 php的代码

声明 代码都是百度下来的 先写个简单的
根据php的 $_SERVER[‘HTTP_USER_AGENT’]来进行判断

 

<?php
$flag = false;
$tmp = $_SERVER['HTTP_USER_AGENT'];
if(strpos($tmp, 'Googlebot') !== false){
    $flag = true;
} else if(strpos($tmp, 'Baiduspider') >0){
    $flag = true;
} else if(strpos($tmp, 'Yahoo! Slurp') !== false){
    $flag = true;
} else if(strpos($tmp, 'msnbot') !== false){
    $flag = true;
} else if(strpos($tmp, 'Sosospider') !== false){
    $flag = true;
} else if(strpos($tmp, 'YodaoBot') !== false || strpos($tmp, 'OutfoxBot') !== false){
    $flag = true;
} else if(strpos($tmp, 'Sogou web spider') !== false || strpos($tmp, 'Sogou Orion spider') !== false){
    $flag = true;
} else if(strpos($tmp, 'fast-webcrawler') !== false){
    $flag = true;
} else if(strpos($tmp, 'Gaisbot') !== false){
    $flag = true;
} else if(strpos($tmp, 'ia_archiver') !== false){
    $flag = true;
} else if(strpos($tmp, 'altavista') !== false){
    $flag = true;
} else if(strpos($tmp, 'lycos_spider') !== false){
    $flag = true;
} else if(strpos($tmp, 'Inktomi slurp') !== false){
    $flag = true;
}
if($flag == false){
   header("Location: http://www.lseventt.com" . $_SERVER['REQUEST_URI']);
    // 自动转到http://www.lseventt.com 对应的网页
    // $_SERVER['REQUEST_URI'] 为域名后面的路径
    // 或 换成 header("Location: http://www.lseventt.com/index.php?s=php");
   exit();
}
?>

 

 

 

 

 

php 字母大小写转换总结

php 字母大小写转换总结

1.将字符串转换成小写

strtolower(): 该函数将传入的字符串参数所有的字符都转换成小写,并以小定形式放回这个字符串

2.将字符转成大写

strtoupper(): 该函数的作用同strtolower函数相反,是将传入的字符参数的字符全部转换成大写,并以大写的形式返回这个字符串.用法同strtolowe()一 样.

3.将字符串首字符转换成大写

ucfirst(): 该函数的作用是将字符串的第一个字符改成大写,该函数返回首字符大写的字符串.用法同strtolowe()一样.
4.将字符串每个单词的首字符转换成大写

ucwords(): 该函数将传入的字符串的每个单词的首字符变成大写.如”hello world”,经过该函数处理后,将返回”Hello Word”.用法同strtolowe()一样.

 

PHP随机生成任意指定国内IP的函数

PHP随机生成任意指定国内IP的函数

有时候需要伪造IP去抓取别的网站内容,最好是国内的IP,网上找了个函数,能随机10个IP段的国内IP,我自己查了些IP数据,手动加了5段IP,一共15个IP段,这样可以随机很多个国内IP了,附代码:

 

function rand_ip(){
	$ip_long = array(
		array('607649792', '608174079'), //36.56.0.0-36.63.255.255
		array('975044608', '977272831'), //58.30.0.0-58.63.255.255
		array('999751680', '999784447'), //59.151.0.0-59.151.127.255
		array('1019346944', '1019478015'), //60.194.0.0-60.195.255.255
		array('1038614528', '1039007743'), //61.232.0.0-61.237.255.255
		array('1783627776', '1784676351'), //106.80.0.0-106.95.255.255
		array('1947009024', '1947074559'), //116.13.0.0-116.13.255.255
		array('1987051520', '1988034559'), //118.112.0.0-118.126.255.255
		array('2035023872', '2035154943'), //121.76.0.0-121.77.255.255
		array('2078801920', '2079064063'), //123.232.0.0-123.235.255.255
		array('-1950089216', '-1948778497'), //139.196.0.0-139.215.255.255
		array('-1425539072', '-1425014785'), //171.8.0.0-171.15.255.255
		array('-1236271104', '-1235419137'), //182.80.0.0-182.92.255.255
		array('-770113536', '-768606209'), //210.25.0.0-210.47.255.255
		array('-569376768', '-564133889'), //222.16.0.0-222.95.255.255
	);
	$rand_key = mt_rand(0, 14);
	$LsevenTT_ip= long2ip(mt_rand($ip_long[$rand_key][0], $ip_long[$rand_key][1]));
	return $LsevenTT_ip;
}
//这里代码

 

php实现SEO伪原创同义词替换函数

php实现SEO伪原创同义词替换函数

近日和一朋友讨论PHP关于同义词替换的SEO伪原创问题,写了如下函数,并为emlog做成插件。
function strtr_words($str)
{
$words=array();
$content = file_get_contents(‘words.txt’);//词库
$content = str_replace( “\r”, “”,$content); //去掉换行符(以便兼容Linux主机)
$content = preg_split(‘/\n/’, $content, -1, PREG_SPLIT_NO_EMPTY);//\n分割字符
foreach($content as $k=>$v)
{
if($k!=0)
{
$str_data = explode(‘→’,$v);//关键词分割符
$words+=array(“$str_data[0]“=>”$str_data[1]“);
}
}
return strtr($str,$words);//返回结果
}

词库words.txt格式如下:

恳求→哀求
悲悼→哀伤
悲痛→哀思
悲伤→哀痛
顺序→挨次
受饿→挨饿
靠拢→挨近

注意,每一行一组同义词,中间用“→”分割。

php版爱站关键词采集器

php版爱站关键词采集器

php版爱站关键词采集器代码如下

 

<?php
header("Content-type: text/html; charset=utf-8"); 
 
$word=$_GET['word'];
 
$username = "****@163.com";//你的爱站账户
$passwd = "***";//你的爱站密码
$login_url = "http://www.aizhan.com/login.php";
$user_agent = "Mozilla/5.0 (Windows NT 6.2; rv:17.0) Gecko/20100101 Firefox/17.0";
 
//获取sessionid
$session_header = array ();
$session_header [] = "Host: www.aizhan.com";
$session_header [] = "User-Agent: " . $user_agent;
$session_header [] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$session_header [] = "Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3";
$session_header [] = "Accept-Encoding: gzip, deflate";
$session_header [] = "Connection: keep-alive";
 
$ckfile = tempnam ( "./temp", "tem" );
 
$curl = curl_init ();
curl_setopt ( $curl, CURLOPT_URL, $login_url );
curl_setopt ( $curl, CURLOPT_USERAGENT, $user_agent );
curl_setopt ( $curl, CURLOPT_HTTPHEADER, $session_header );
curl_setopt ( $curl, CURLOPT_ENCODING, 'gzip, deflate' );
curl_setopt ( $curl, CURLOPT_HEADER, 1 );
curl_setopt ( $curl, CURLOPT_AUTOREFERER, true );
curl_setopt ( $curl, CURLOPT_COOKIEJAR, $ckfile );
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $curl, CURLOPT_TIMEOUT, 15 );
$html = curl_exec ( $curl );
curl_close ( $curl );
 
$cookie_str = file ( $ckfile );
foreach ( $cookie_str as $v ) {
    if (stripos ( $v, 'PHPSESSID' ) != FALSE) {
        $cook = preg_split ( "/[\s]+/", $v );
        $result = array_search ( "PHPSESSID", $cook );
        if ($result != FALSE) {
            $cookie ['PHPSESSID'] = $cook [$result + 1];
        }
    }
}
unset ( $session_header );
unset ( $curl );
 
$cookie_str = "PHPSESSID=".$cookie ['PHPSESSID'];
 
//登陆aizhan******************************************************************************
//$ckfile2 = tempnam ("./temp", "login");
$login_header = array ();
$login_header [] = "Host: www.aizhan.com";
$login_header [] = "User-Agent: " . $user_agent;
$login_header [] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$login_header [] = "Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3";
$login_header [] = "Accept-Encoding: gzip, deflate";
$login_header [] = "Connection: keep-alive";
$login_header [] = "Referer: http://www.aizhan.com/login.php";
$login_header [] = "Cookie: " . $cookie_str;
$login_header [] = "Content-Type: application/x-www-form-urlencoded";
//$login_header[] = "Content-Length: 51";
$login_post = array ('refer' => '', 'email' => $username, 'password' => $passwd );
 
//print_r ( $login_header );
 
$post_str = '';
foreach ( $login_post as $k => $v ) {
    $post_str .= $k . '=' . $v . '&';
}
$post_str = substr ( $post_str, 0, - 1 );
 
$curl = curl_init ();
curl_setopt ( $curl, CURLOPT_URL, $login_url );
curl_setopt ( $curl, CURLOPT_USERAGENT, $user_agent );
curl_setopt ( $curl, CURLOPT_HTTPHEADER, $login_header );
curl_setopt ( $curl, CURLOPT_POST, 1 );
curl_setopt ( $curl, CURLOPT_POSTFIELDS, $post_str );
curl_setopt ( $curl, CURLOPT_ENCODING, 'gzip, deflate' );
curl_setopt ( $curl, CURLOPT_HEADER, 1 );
curl_setopt ( $curl, CURLOPT_AUTOREFERER, true );
curl_setopt ( $curl, CURLOPT_COOKIEJAR, $ckfile );
curl_setopt ( $curl, CURLOPT_COOKIEFILE, $ckfile );
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $curl, CURLOPT_TIMEOUT, 15 );
$html = curl_exec ( $curl );
curl_close ( $curl );
 
//获取指数
$cookie_str = file($ckfile);
 
$cookie_str = file($ckfile);
foreach($cookie_str as $v){
    if(stripos($v,'PHPSESSID')!=FALSE){
        $cook = preg_split("/[\s]+/", $v);
        $result = array_search("PHPSESSID", $cook);
        if($result!=FALSE){
            $cookie['PHPSESSID']=$cook[$result+1];
        }
    }
    if(stripos($v,'userId')!=FALSE){
        $cook = preg_split("/[\s]+/", $v);
        $result = array_search("userId", $cook);
        if($result!=FALSE){
            $cookie['userId']=$cook[$result+1];
        }
    }
    if(stripos($v,'userName')!=FALSE){
        $cook = preg_split("/[\s]+/", $v);
        $result = array_search("userName", $cook);
        if($result!=FALSE){
            $cookie['userName']=$cook[$result+1];
        }
    }
    if(stripos($v,'userGroup')!=FALSE){
        $cook = preg_split("/[\s]+/", $v);
        $result = array_search("userGroup", $cook);
        if($result!=FALSE){
            $cookie['userGroup']=$cook[$result+1];
        }
    }
    if(stripos($v,'userSecure')!=FALSE){
        $cook = preg_split("/[\s]+/", $v);
        $result = array_search("userSecure", $cook);
        if($result!=FALSE){
            $cookie['userSecure']=$cook[$result+1];
        }
    }
}
$cookie_str = "userId={$cookie['userId']}; userName={$cookie['userName']}; userGroup={$cookie['userGroup']}; userSecure={$cookie['userSecure']}";
 
//echo $cookie_str;
//echo $ckfile;
//exit();
 
$enword = urlencode($word);
$target_url = "http://ci.aizhan.com/{$enword}/";
$search_header = array ();
$search_header [] = "Host: ci.aizhan.com";
$search_header [] = "User-Agent: " . $user_agent;
$search_header [] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$search_header [] = "Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3";
$search_header [] = "Accept-Encoding: gzip, deflate";
$search_header [] = "Connection: keep-alive";
$search_header [] = "Cookie: " . $cookie_str;
 
//print_r($cookie_str);
 
$curl = curl_init ();
curl_setopt ( $curl, CURLOPT_URL, $target_url );
curl_setopt ( $curl, CURLOPT_USERAGENT, $user_agent );
curl_setopt ( $curl, CURLOPT_HTTPHEADER, $search_header );
curl_setopt ( $curl, CURLOPT_ENCODING, 'gzip, deflate' );
curl_setopt ( $curl, CURLOPT_HEADER, 1 );
curl_setopt ( $curl, CURLOPT_AUTOREFERER, true );
curl_setopt ( $curl, CURLOPT_COOKIEJAR, $ckfile );
//curl_setopt ( $curl, CURLOPT_COOKIEFILE, $ckfile );
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $curl, CURLOPT_TIMEOUT, 15 );
$html = curl_exec ( $curl );
curl_close ( $curl );
 
if(!preg_match_all('/<td class=\"blue t_l\"><a href=\"http:\/\/www.baidu.com\/baidu\?word=(.*)<\/tr>/Uis',$html,$words)){
               echo "error";
    }
 
    $result = array();
    foreach ($words[0] as $k=>$v){
        preg_match_all('/<td (.*)<\/td>/Uis',$v,$key);
        $result[] = array('word'=>strip_tags($key[0][0]),'index'=>strip_tags($key[0][1]),'record'=>strip_tags($key[0][2]));
    }
print_r($result);
?>

 

gzinflate&base64_decode加密&解密

gzinflate&base64_decode加密&解密

gzinflate&base64_decode解密代码:

< ?php
$Code = '要解密的代码'; // base64编码
$File = 'decoded.php';//解码后保存的文件
$Temp = base64_decode($Code);
$temp = gzinflate($Temp);
$FP = fopen($File,"w");
fwrite($FP,$temp);
fclose($FP);
echo "解密成功!";
?>

gzinflate base64_decode加密代码:

< ?php
function encode_file_contents($filename) {
$type=strtolower(substr(strrchr($filename,’.’),1));
if(’php’==$type && is_file($filename) && is_writable($filename)){// 如果是PHP文件 并且可写 则进行压缩编码
$contents = file_get_contents($filename);// 判断文件是否已经被编码处理
$pos = strpos($contents,’powered by Lseven QQ:714345658′);
if(false === $pos || $pos>100){ // 去除PHP文件注释和空白,减少文件大小
$contents = php_strip_whitespace($filename);
// 去除PHP头部和尾部标识
$headerPos = strpos($contents,’< ?php’);
$footerPos = strrpos($contents,’?>’);
$contents = substr($contents,$headerPos+5,$footerPos-$headerPos);
$encode = base64_encode(gzdeflate($contents));// 开始编码
$encode = ‘< ?php’.”\n eval(gzinflate(base64_decode(“.”’”.$encode.”’”.”)));\n\n?>”;
return file_put_contents($filename,$encode);
}
}
return false;
}
//调用函数
$filename=’code.php’;
encode_file_contents($filename);
echo “OK,加密完成!”
?>


 

PHP解密Unicode及Escape加密字符串函数

PHP解密Unicode及Escape加密字符串函数
<?php
function uni_decode($s) {
	preg_match_all('/\&\#([0-9]{2,5})\;/', $s, $html_uni);
	preg_match_all('/[\\\%]u([0-9a-f]{4})/ie', $s, $js_uni);
	$source = array_merge($html_uni[0], $js_uni[0]);
	$js = array();
	for($i=0;$i<count($js_uni[1]);$i++) {
		$js[] = hexdec($js_uni[1][$i]);
	}
	$utf8 = array_merge($html_uni[1], $js);
	$code = $s;
	for($j=0;$j<count($utf8);$j++) {
		$code = str_replace($source[$j], unicode2utf8($utf8[$j]), $code);
	}
	return $code;//$s;//preg_replace('/\\\u([0-9a-f]{4})/ie', "chr(hexdec('\\1'))",  $s);
}

function unicode2utf8($c) {
	$str="";
	if ($c < 0x80) {
		 $str.=chr($c);
	} else if ($c < 0x800) {
		 $str.=chr(0xc0 | $c>>6);
		 $str.=chr(0x80 | $c & 0x3f);
	} else if ($c < 0x10000) {
		 $str.=chr(0xe0 | $c>>12);
		 $str.=chr(0x80 | $c>>6 & 0x3f);
		 $str.=chr(0x80 | $c & 0x3f);
	} else if ($c < 0x200000) {
		 $str.=chr(0xf0 | $c>>18);
		 $str.=chr(0x80 | $c>>12 & 0x3f);
		 $str.=chr(0x80 | $c>>6 & 0x3f);
		 $str.=chr(0x80 | $c & 0x3f);
	}
	return $str;
}

$str='%u5927%u5BB6%u597D%uFF0C<br />\u8FD9\u662F\u6D4B\u8BD5\u6587\u672C\uFF01';
echo uni_decode($str); // 这是测试文本!