分类归档:Web相关

centos安装VNCserver以及火狐和flash插件

1.安装vncserver

install_vnc_server

2. 安装火狐

yum -y install firefox

3.安装flash插件
wget http://fpdownload.macromedia.com/get/flashplayer/pdc/11.2.202.310/install_flash_player_11_linux.x86_64.tar.gz
tar zxvf install_flash_player_11_linux.x86_64.tar.gz
mkdir -p ~/.mozilla/plugins/
cp libflashplayer.so ~/.mozilla/plugins/

 

 

 


			

常用的PHP采集

//取图片
preg_match_all('/<div class=\"conlist\">(.*?)<div class="ft">/is',$content,$imgcontent);
$content=$imgcontent[0][0];
preg_match_all('/<div class=\"pic\"\>(.*?)<\/div\>/is',$content,$imgcontent);
$imgcontent=$imgcontent[0];
if($imgcontent){
	$i=0;
    foreach($imgcontent as $value){	
		preg_match('/<img src=\"(.*?)\" alt=/is',$value,$imghref);
		$product[$i][img]=$imghref[1];
	    $i++;
	}
}

//取产品介绍
preg_match_all('/<br clear=\"all\"\/>(.*?)<a href=\"/is',$content,$infocontent);
$infocontent=$infocontent[1];
if($infocontent){
	$i=0;
    foreach($infocontent as $value){
		$product[$i][info]=trim($value);
	    $i++;
	}
}

//取产品名称
preg_match_all('/class=\"title\" id=\"proName_(.*?)\">(.*?)<\/a>/is',$content,$namecontent);
$infocontent=$namecontent[2];
if($infocontent){
	$i=0;
    foreach($infocontent as $value){
		$product[$i][name]=trim($value);
	    $i++;
	}
}

//取产品价格
preg_match_all('/<span class=\"price\">(.*?)<\/span>/is',$content,$pricecontent);
$pricecontent=$pricecontent[1];
//print_r($pricecontent);
if($pricecontent){
	$i=0;
    foreach($pricecontent as $value){
		preg_match('/<b >(.*?)<\/b>/is',$value,$imgpai);
		$product[$i][price]=$imgpai[1];
	    $i++;
	}
}

 

ECshop前台分页

代码如下:

---------------------------------------在要分页的sql上面加上如下代码 ----------------------------------------------------

$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
$record_count = $db->getOne('总数的sql语句');
//例如 $record_count = $db->getOne('select count(*) from '.$ecs->table('goods'));
$pager = get_pager('php页面', php页面的参数 , $record_count, $page,每页显示几个,分页样式);
//例如 $pager = get_pager('test.php', array('act' => $_REQUEST['act'],'id' => $_REQUEST['id']), $record_count, $page,5,0);
$smarty->assign('pager', $pager);

//分页的sql语句

$sql= 分页sql语句.' LIMIT '.$pager['start'].','.$pager['size'];

//例如 $sql= 'select count(*) from '.$ecs->table('goods').' LIMIT '.$pager['start'].','.$pager['size'];

------------------------------------------------------------------get_pager 方法----------------------------------------------

function get_pager($url, $param, $record_count, $page = 1, $size = 10, $styleid=1)
{
    $size = intval($size);
    if ($size < 1)
    {
        $size = 10;
    }

    $page = intval($page);
    if ($page < 1)
    {
        $page = 1;
    }

    $record_count = intval($record_count);

    $page_count = $record_count > 0 ? intval(ceil($record_count / $size)) : 1;
    if ($page > $page_count)
    {
        $page = $page_count;
    }
    /* 分页样式 */
    $pager['styleid'] = $styleid;

    $page_prev = ($page > 1) ? $page - 1 : 1;
    $page_next = ($page < $page_count) ? $page + 1 : $page_count;

    /* 将参数合成url字串 */
    $param_url = '?';
    foreach ($param AS $key => $value)
    {
        $param_url .= $key . '=' . $value . '&';
    }

    $pager['url']          = $url;
    $pager['start']        = ($page -1) * $size;
    $pager['page']         = $page;
    $pager['size']         = $size;
    $pager['record_count'] = $record_count;
    $pager['page_count']   = $page_count;

    if ($pager['styleid'] == 0)
    {
        $pager['page_first']   = $url . $param_url . 'page=1';
        $pager['page_prev']    = $url . $param_url . 'page=' . $page_prev;
        $pager['page_next']    = $url . $param_url . 'page=' . $page_next;
        $pager['page_last']    = $url . $param_url . 'page=' . $page_count;
        $pager['array'] = array();
        for ($i = 1; $i <= $page_count; $i++)
        {
            $pager['array'][$i] = $i;
        }
    }
    else
    {
        $_pagenum = 10;     // 显示的页码
        $_offset = 2;       // 当前页偏移值
        $_from = $_to = 0; // 开始页, 结束页
        if($_pagenum > $page_count)
        {
            $_from = 1;
            $_to = $page_count;
        }
        else
        {
            $_from = $page - $_offset;
            $_to = $_from + $_pagenum - 1;
            if($_from < 1)
            {
                $_to = $page + 1 - $_from;
                $_from = 1;
                if($_to - $_from < $_pagenum)
                {
                    $_to = $_pagenum;
                }
            }
            elseif($_to > $page_count)
            {
                $_from = $page_count - $_pagenum + 1;
                $_to = $page_count;
            }
        }
        $url_format = $url . $param_url . 'page=';
        $pager['page_first'] = ($page - $_offset > 1 && $_pagenum < $page_count) ? $url_format . 1 : '';
        $pager['page_prev'] = ($page > 1) ? $url_format . $page_prev : '';
        $pager['page_next'] = ($page < $page_count) ? $url_format . $page_next : '';
        $pager['page_last'] = ($_to < $page_count) ? $url_format . $page_count : '';
        $pager['page_kbd'] = ($_pagenum < $page_count) ? true : false;
        $pager['page_number'] = array();
        for ($i=$_from;$i<=$_to;++$i)
        {
            $pager['page_number'][$i] = $url_format . $i;
        }
    }
    $pager['search'] = $param;

    return $pager;
}

------------------------------------------------------ html 分页代码 ---------------------------------------------------------

<!--翻页 start-->
<form name="selectPageForm" action="{$smarty.server.PHP_SELF}" method="get">
<!-- {if $pager.styleid eq 0 } -->
<div id="pager">
总计{$pager.record_count}个记录,共{$pager.page_count} 页。 <span> <a href="{$pager.page_first}">{$lang.page_first}</a> <a href="{$pager.page_prev}">{$lang.page_prev}</a> <a href="{$pager.page_next}">{$lang.page_next}</a> <a href="{$pager.page_last}">{$lang.page_last}</a> </span>
    <!--{foreach from=$pager.search key=key item=item}-->
      {if $key eq 'keywords'}
          <input type="hidden" name="{$key}" value="{$item|escape:decode_url}" />
        {else}
          <input type="hidden" name="{$key}" value="{$item}" />
      {/if}
    <!--{/foreach}-->
    <select name="page" id="page" onchange="selectPage(this)">
    {html_options options=$pager.array selected=$pager.page}
    </select>
</div>
<!--{else}-->
<div id="pager" class="pagebar">
<span class="f_l f6" style="margin-right:10px;">总计<b>{$pager.record_count}</b> 个记录</span>
<!-- {if $pager.page_first} --><a href="{$pager.page_first}">{$lang.page_first} ...</a><!-- {/if} -->
<!-- {if $pager.page_prev} --><a class="prev" href="{$pager.page_prev}">{$lang.page_prev}</a><!-- {/if} -->
<!-- {if $pager.page_count neq 1} -->
    <!--{foreach from=$pager.page_number key=key item=item}-->
      <!-- {if $pager.page eq $key} -->
      <span class="page_now">{$key}</span>
      <!-- {else} -->
      <a href="{$item}">[{$key}]</a>
      <!-- {/if} -->
    <!--{/foreach}-->
<!-- {/if} -->
<!-- {if $pager.page_next} --><a class="next" href="{$pager.page_next}">{$lang.page_next}</a><!-- {/if} -->
<!-- {if $pager.page_last} --><a class="last" href="{$pager.page_last}">...{$lang.page_last}</a><!-- {/if} -->
<!-- {if $pager.page_kbd} -->
    <!--{foreach from=$pager.search key=key item=item}-->
      {if $key eq 'keywords'}
          <input type="hidden" name="{$key}" value="{$item|escape:decode_url}" />
        {else}
          <input type="hidden" name="{$key}" value="{$item}" />
      {/if}
    <!--{/foreach}-->
    <kbd style="float:left; margin-left:8px; position:relative; bottom:3px;"><input type="text" name="page" onkeydown="if(event.keyCode==13)selectPage(this)" size="3" class="B_blue" /></kbd>
    <!-- {/if} -->
</div>
<!-- {/if} -->
</form>
<!--翻页 END-->

 

PHP生成文字水印代码

<?php

setWater('img/999.jpg','',"for:小梅 为什么放弃治疗!",'105,0,0',2,'FZLBJW.TTF','text',24);
/*
$imgSrc:目标图片,可带相对目录地址,
$markImg:水印图片,可带相对目录地址,支持PNG和GIF两种格式,如水印图片在执行文件mark目录下,可写成:mark/mark.gif
$markText:给图片添加的水印文字
$TextColor:水印文字的字体颜色
$markPos:图片水印添加的位置,取值范围:0~9
0:随机位置,在1~8之间随机选取一个位置
1:顶部居左 2:顶部居中 3:顶部居右 4:左边居中
5:图片中心 6:右边居中 7:底部居左 8:底部居中 9:底部居右
$fontType:具体的字体库,可带相对目录地址
$markType:图片添加水印的方式,img代表以图片方式,text代表以文字方式添加水印
$fontSize: 字体大小
*/
function setWater($imgSrc,$markImg,$markText,$TextColor,$markPos,$fontType,$markType,$fontSize)
{
    $srcInfo = @getimagesize($imgSrc);
    $srcImg_w = $srcInfo[0];
    $srcImg_h = $srcInfo[1];
    switch ($srcInfo[2]) 
    { 
        case 1: 
            $srcim =imagecreatefromgif($imgSrc); 
            break; 
        case 2: 
            $srcim =imagecreatefromjpeg($imgSrc); 
            break; 
        case 3: 
            $srcim =imagecreatefrompng($imgSrc); 
            break; 
        default: 
            die("不支持的图片文件类型"); 
            exit; 
    }

    if(!strcmp($markType,"img"))
    {
        if(!file_exists($markImg) || empty($markImg))
        {
            return;
        }

        $markImgInfo = @getimagesize($markImg);
        $markImg_w    = $markImgInfo[0];
        $markImg_h    = $markImgInfo[1];

        if($srcImg_w < $markImg_w || $srcImg_h < $markImg_h)
        {
            return;
        }

        switch ($markImgInfo[2]) 
        { 
            case 1: 
                $markim =imagecreatefromgif($markImg); 
                break; 
            case 2: 
                $markim =imagecreatefromjpeg($markImg); 
                break; 
            case 3: 
                $markim =imagecreatefrompng($markImg); 
                break; 
            default: 
                die("不支持的水印图片文件类型"); 
                exit; 
        }

        $logow = $markImg_w;
        $logoh = $markImg_h;
    }

    if(!strcmp($markType,"text"))
    {
        // $fontSize = 16;
        if(!empty($markText))
        {
            if(!file_exists($fontType))
            {
                return;
            }
        }
        else {
            return;
        }

        $box = @imagettfbbox($fontSize, 0, $fontType,$markText);
        $logow = max($box[2], $box[4]) - min($box[0], $box[6]);
        $logoh = max($box[1], $box[3]) - min($box[5], $box[7]);
    }

    if($markPos == 0)
    {
        $markPos = rand(1, 9);
    }

    switch($markPos)
    {
        case 1:
            $x = +5;
            $y = +5;
            break;
        case 2:
            $x = ($srcImg_w - $logow) / 2;
            $y = +5+45;
            break;
        case 3:
            $x = $srcImg_w - $logow - 5;
            $y = +15;
            break;
        case 4:
            $x = +5;
            $y = ($srcImg_h - $logoh) / 2;
            break;
        case 5:
            $x = ($srcImg_w - $logow) / 2;
            $y = ($srcImg_h - $logoh) / 2;
            break;
        case 6:
            $x = $srcImg_w - $logow - 5;
            $y = ($srcImg_h - $logoh) / 2;
            break;
        case 7:
            $x = +5;
            $y = $srcImg_h - $logoh - 5;
            break;
        case 8:
            $x = ($srcImg_w - $logow) / 2;
            $y = $srcImg_h - $logoh - 5;
            break;
        case 9:
            $x = $srcImg_w - $logow - 5;
            $y = $srcImg_h - $logoh -5;
            break;
        default: 
            echo ("此位置不支持"); 
            exit;
    }

    $dst_img = @imagecreatetruecolor($srcImg_w, $srcImg_h);

    imagecopy ( $dst_img, $srcim, 0, 0, 0, 0, $srcImg_w, $srcImg_h);

    if(!strcmp($markType,"img"))
    {
        imagecopy($dst_img, $markim, $x, $y, 0, 0, $logow, $logoh);
        imagedestroy($markim);
    }

    if(!strcmp($markType,"text"))
    {
        $rgb = explode(',', $TextColor);

        $color = imagecolorallocate($dst_img, $rgb[0], $rgb[1], $rgb[2]);
        imagettftext($dst_img, $fontSize, 0, $x, $y, $color, $fontType,$markText);
    } 
    switch ($srcInfo[2]) 
    { 
        case 1:
            // imagegif($dst_img, $imgSrc); 
			header("content-type: image/gif");
            imagegif($dst_img); 
            break; 
        case 2: 
            // imagejpeg($dst_img, $imgSrc); 
			header("content-type: image/jpeg");
            imagejpeg($dst_img); 
            break; 
        case 3: 
            // imagepng($dst_img, $imgSrc); 
			header("content-type: image/png");
            imagepng($dst_img); 
            break;
        default: 
            die("不支持的水印图片文件类型"); 
            exit; 
    }

    imagedestroy($dst_img);
    imagedestroy($srcim);
}

?>

 

wordpress去除wordpress.org增加登陆框

首先找到这个文件,位于/wp-includes/下的default-widgets.php

去掉wordpress.org,删除

<li><a href="http://wordpress.org/" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>

删除RSS

<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo esc_attr(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>

 

<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo esc_attr(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>

删除 <li><?php wp_loginout(); ?></li> 这段代码,然后改为如下代码

<li><?php if (!(current_user_can('level_0'))){ ?>
<form action="<?php echo get_option('home'); ?>/wp-login.php" method="post">
<input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="20" /><br />
<input type="password" name="pwd" id="pwd" size="20" /><br>
<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> 记住密码</label>
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" /> <input type="submit" name="submit" value="登录" class="button" />
</p>
</form>
<a href="<?php echo get_option('home'); ?>/wp-login.php?action=lostpassword">忘记密码</a>
<?php } else { ?>
<a href="<?php echo wp_logout_url( get_bloginfo('url') ); ?>" title="">退出登录</a>
<?php }?></li>

 

 

以前做的采集QQ号码程序

<?php
header("Content-type: text/html; charset=utf-8");
require_once 'database.php';
//set_time_limit(0);
//ignore_user_abort();
function writelog($log){
	$log_file="rizhi.txt";
	$fp = fopen($log_file,'a');
	fwrite($fp,date("Y-m-d H:i:s",time())."		".$log."\r\n");
	fclose($fp);
}
function writelog2($log){
	$log_file="QQMAIL.txt";
	$fp = fopen($log_file,'a');
	fwrite($fp,$log."\r\n");
	fclose($fp);
}
ignore_user_abort();           // 即使Client断开(如关掉浏览器),PHP脚本也可以继续执行.
set_time_limit(0);             // 执行时间为无限制,php默认的执行时间是30秒,通过set_time_limit(0)可以让程序无限制的执行下去

$bb = 0 ;
writelog('开始采集!');
echo '开始采集!<br><hr>';

for($nl=24;$nl<=30;$nl++){//年龄
	$nl++;
	$nl2=$nl +1;
	for($yue=1;$yue<=12;$yue++){//月
		for($ri=1;$ri<=31;$ri++){//日
			for($i=0;$i<100;$i++){//页数
				$jishu =$i+1;
				echo "<font color = red>最低年龄:".$nl."最高年龄:".$nl2."     ".$yue."月".$ri."日  ".$jishu."%</font>";
				echo "<br>";
				writelog("最低年龄:".$nl."最高年龄:".$nl2."     ".$yue."月".$ri."日  第".$i."页");
				$url="http://soren.qzone.qq.com/cgi-bin/soren/cgi_userinfo_search?sex=-1&a1=".$nl."&a2=".$nl2."&pv=11&ct=1100&hp=0&hc=0&at=-1&month=".$yue."&day=".$ri."&mr=-1&bt=-1&cr=&cn=&cap=0&cac=0&idol=&game=&it=&sport=&book=&tv=&cloth=&cosm=&place=&interest=&begin=".$i."&bSimple=0";
				$ch = curl_init();
				curl_setopt ($ch, CURLOPT_URL, $url);
				curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
				curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
				$content = curl_exec($ch);
				preg_match_all('/id=\"portrait_(.*?)\" onclick/is',$content,$qq);
				foreach($qq[1] as $value){

					$coolaj = trim($value)."@qq.com";
					$sql = "select * from mail where mails = '".$coolaj."'";
					$rs2 = mysql_query($sql, $connect) or die("Invalid query: " . mysql_error());
					$cool =  mysql_fetch_row ($rs2);
					if(is_array($cool)){
						writelog("插入失败->".$coolaj."已经存在!");
					}else{
						$rs = mysql_query("insert into mail VALUES('','".$coolaj."','".$i."','QQ采集')", $connect) or die("Invalid query: " . mysql_error());
						if($rs){
							$bb++;
							echo $showtime=date("Y-m-d H:i:s");
							echo "插入<font color=red>第".$bb."个</font><font color=blue>".$coolaj."</font>成功!<br>";
							writelog("插入第".$bb."个".$coolaj."成功!");
							writelog2($coolaj);
						}else{
							writelog("插入".$coolaj."失败!");
						}
					}

				}
			}
		}
	}
}
echo "<script>alert('采集完成!')</script>";

 

<?php
$_POST=sql_injection($_POST);
$_GET=sql_injection($_GET);
function sql_injection($content)
{
 if (get_magic_quotes_gpc())
 {
  if (is_array($content))
  {
   foreach ($content as $key=>$value)
   {
    $content[$key] = str_replace("'","\"",stripslashes($value));
   }
  }
  else
  {
    $content[$key] = str_replace("'","\"",stripslashes($content));
  }
 }
 return $content;
}

$hostname_conn = "localhost";
$database_conn = "test";
$username_conn = "root";
$password_conn = "";
$connect = mysql_pconnect($hostname_conn, $username_conn, $password_conn,true) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_conn, $connect);
mysql_query("set NAMES 'UTF8'");
date_default_timezone_set('PRC');
?>

 

PHP屏蔽查找关键字程序

<?php
function keyWordCheck($str){
	// 去除空白
	$str = trim($str);
	// 读取关键字文本
	$content = @file_get_contents('000.txt');
	// 转换成数组
	$arr = explode("\n", $content);
	// var_dump($arr);
	// 遍历检测
	for($i=0,$k=count($arr);$i<$k;$i++){
		// 如果此数组元素为空则跳过此次循环
		if($arr[$i]==''){
			continue; 
		} 
		// 如果检测到关键字,则返回匹配的关键字,并终止运行
		if(strpos($str,trim($arr[$i]))!==false){
			return $arr[$i];
		} 
	}
	// 如果没有检测到关键字则返回false 
	return false;
}

$content = '王涵万';

if ( keyWordCheck($content) ){
	echo "存在关键字! ";
}else{
	echo "不存在关键字! ";
}

?>

 

解析PHP自带的进位制之间的转换函数

bindec() — 二进制转换为十进制

decbin() — 十进制转换为二进制

dechex() — 十进制转换为十六进制

decoct() — 十进制转换为八进制

hexdec() — 十六进制转换为十进制

octdec() — 八进制转换为十进制

base_convert($id,10,16)– 在任意进制之间转换数字 (10->16)

PHP判断输入是否为中文

if   (preg_match("/^[\x7f-\xff]+$/", $str)) { //兼容gb2312,utf-8
     return true;
} else {
     return false;
}