LINUX中PHP实现网页截屏实例程序

 更新时间:2016年11月25日 16:20  点击:1775
网页截屏以前我们只能在asp.net中实现,下面我来介绍在linux中利用一个插件让php也可以实现网页截屏吧,希望对大家有帮助。

服务器端

为实现截图的程序必须借助服务器端程序:http://code.google.com/p/wkhtmltopdf/

可将网页转换为pdf或者图片,32和64位有区别,找个适合自己服务器的版本。

安装

安装过程十分简单:解压 -> 找个合适的路径放下…

执行

命令行调用1

 代码如下 复制代码
/servers/app/qtwebkit/wkHtmlToImage 111cn.net www.111cn.net.png

默认的清晰度比较高,图片会很大,生成图片需要一定的时间。

php

 代码如下 复制代码

exec('/servers/app/qtwebkit/wkHtmlToImage 111cn.net www.111cn.net.png');

具体的使用方法

 代码如下 复制代码

<?php
ob_start();
//如果将输出的文件名设置为'-',则直接返回文件数据流
passthru('/servers/app/qtwebkit/wkHtmlToImage --width 800 --height 600 -quality 85 weibo.com -');
$fileName = self::cachePath() . '/' . self::name();
$content = ob_get_clean();
 
//写入图片文件,备用
//file_put_contents($fileName, $content);
 
//直接输出为图片
header("Content-type: image/png");
echo $content;
?>

中文乱码问题

主要看服务器是否支持中文语言,如果截图中出现乱码,直接装个中文包就好了。

 代码如下 复制代码

yum install fonts-chinese

本程序可以实现批量替换目录中所有文件中的内容或用于打量给挂了木马文件批量替换与更新了,希望文章对各位同学有所帮助。
 代码如下 复制代码


<?php
/***************************************************************************
                             batch-replace, v1.1
 ***************************************************************************
    file:                batch-replace_utf8.php
    functionality:       本程序可以扫描指定目录的所有文件,进行内容替换。可用于被批量挂马的删除以及批量更新页面某些内容。
                         本程序适用于对UTF-8的页面进行修改。
                        
 

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/
 
set_time_limit(3600);


if($_POST['Submit']=='开始执行操作'){
  $dir = $_POST['searchpath'];
  $shortname = $_POST['shortname'];
  $isall = $_POST['isall'];
  $isreg = $_POST['isreg'];
 
if (!get_magic_quotes_gpc()) {
  $sstr = $_POST['sstr'];
  $rpstr = $_POST['rpstr'];
} else {
  $sstr = stripslashes($_POST['sstr']);
  $rpstr = stripslashes($_POST['rpstr']);
}   
 

  //分析shortname
  $arrext = explode ("|",$shortname);


  if (!is_dir($dir)) return;
  if ($sstr == '') return;

  //把末尾的/去掉
  if(substr($dir,-1)=='/') $dir = substr($dir,0,strrpos($dir,"/"));

  //罗列所有目录
  if ($isall == 1){
    hx_dirtree($dir);
  }else{
    hx_dealdir($dir);

  }

exit();
}


function hx_dirtree($path="."){
  global $sstr,$rpstr,$isreg,$arrext;


  $d = dir($path);
  while(false !== ($v = $d->read())) {
    if($v == "." || $v == "..") continue;
    $file = $d->path."/".$v;
    if(is_dir($file)) {
      echo "<p>$v</p>"; hx_dirtree($file);
    }else{
        $ext=substr(strrchr($v,"."), 1);
        if( in_array($ext , $arrext) ){
          echo "<li>$file ";
          $body = file_get_contents($file);
          if($isreg == 1){
          $body2 = preg_replace($sstr, $rpstr, $body);
          }else{
          $body2 = str_replace($sstr, $rpstr, $body);
          }
          if($body != $body2 && $body2 != ''){
            tofile($file,$body2);
            echo ' OK';
          }else{
            echo ' NO';
          }
          echo '</li>';
        }
    }
  }
  $d->close();
}

function hx_dealdir($dir){
  global $sstr,$rpstr,$isreg,$arrext;
    if ($dh = opendir($dir)) {
    while (false !== ($file = readdir($dh))) {
      if(filetype($dir.'/'.$file)=='file'){

        $ext=substr(strrchr($file,"."), 1);
        if( in_array($ext , $arrext) ){

          echo "<li>$file ";
          $body = file_get_contents($dir.'/'.$file);       
          if($isreg == 1){
          $body2 = preg_replace($sstr, $rpstr, $body);
          }else{
          $body2 = str_replace($sstr, $rpstr, $body);
          }
          if($body != $body2 && $body2 != ''){           
            tofile($dir.'/'.$file,$body2);
            echo ' OK';
          }else{
            echo ' NO';
          }
          echo '</li>';
        }
      }
    }
    closedir($dh);
    }

}
//把生成文件的过程写出函数
function tofile($file_name,$file_content){
 if (is_file ($file_name)){
  @unlink ($file_name);
 }
  $handle = fopen ($file_name,"w");
  if (!is_writable ($file_name)){
    return false;
  }
  if (!fwrite ($handle,$file_content)){
    return false;
  }
  fclose ($handle); //关闭指针
  return $file_name;
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>批量替换程序|木马批量删除_www.itlearner.com</title>
<style type="text/css">
body{background:#FFFFFF;color:#000;font-size:12px;}
#top{text-align:center;}
h1,p,form{margin:0;padding:0;}
h1{font-size;14px;}
</style>
</head>
<body>
  <div id="top">
<h1>批量替换程序(UTF-8版)</h1>
<div>本程序可以扫描指定目录的所有文件,进行<strong>内容替换</strong>。可用于被批量挂马的删除以及批量更新页面某些内容。<br/>
在文件数量非常多的情况下,本操作比较占用服务器资源,请确脚本超时限制时间允许更改,否则可能无法完成操作。</div>
  </div>


<form action="<?=$_SERVER['SCRIPT_NAME']?>" name="form1" target="stafrm" method="post">
<table width="95%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#666666">
  <tr>
    <td width="10%" bgcolor="#FFFFFF"><strong>&nbsp;起始根路径:</strong></td>
    <td width="90%" bgcolor="#FFFFFF"><input name="searchpath" type="text" id="searchpath" value="./test" size="20" />
      点表示当前目录,末尾不要加/ <input type="checkbox" name="isall" value="1" />包含此目录下所有目录</td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF"><strong>&nbsp;文件扩展名:</strong></td>
    <td bgcolor="#FFFFFF"><input name="shortname" type="text" id="shortname" size="20" value="php|htm" />
      多个请用|隔开</td>
  </tr>
  <tr id="rpct">
    <td height="64" colspan="2" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="1" cellpadding="1">
      <tr bgcolor="#EDFCE2">
        <td colspan="4"><strong>内容替换选项:</strong> <input type="checkbox" name="isreg" value="1" />使用正则表达式</td>
      </tr>
      <tr>
        <td colspan="4">替换内容类默认使用字符串替换,也可以使用正则表达式(需勾选)。"替换为"不填写的话,就表示删除"替换内容"。</td>
      </tr>
      <tr>
        <td width="10%">&nbsp;替换内容:</td>
        <td width="36%"><textarea name="sstr" id="sstr" style="width:90%;height:45px"></textarea></td>
        <td width="10%">替 换 为:</td>
        <td><textarea name="rpstr" id="rpstr" style="width:90%;height:45px"></textarea></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan="2" height="20" align="center" bgcolor="#E2F5BC"><input type="submit" name="Submit" value="开始执行操作" class="inputbut" /></td>
  </tr>
</table>
  </form>
<table width="95%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#666666">
  <tr bgcolor="#FFFFFF">
    <td id="mtd">
     <div id='mdv' style='width:100%;height:100;'>
        <iframe name="stafrm" frameborder="0" id="stafrm" width="100%" height="100%"></iframe>
      </div>
      <script type="text/javascript">
     document.all.mdv.style.pixelHeight = screen.height - 450;
     </script>    </td>
  </tr>
</table>

</body>
</html>

有时我在测试或其它应用时希望能快速的清除memcache缓存,下面我来总结了几种清除memcache中的缓存的一些方法,希望方法对大家有所哦

以前有同事需要我清除memcache缓存,我总是直接使用kill命令结束掉这个进程,后来才知道有更简单的方法,来清除memcachd的缓存,记录一下,以备不时之需:

1.首先使用ssh命令登录到memcached所在服务器,命令如下:

 代码如下 复制代码

#ssh root@192.168.1.1

输入root密码后可登录对应的服务器;

2.使用telnet命令后接tomcat服务配置文件中指定的memcached启动端口:

 代码如下 复制代码

#telnet localhost 11211

之后显示:

Trying 127.0.0.1…
Connected to localhost.localdomain (127.0.0.1).
Escape character is ‘^]’.

3.此时输入如下内容并回车即可清除缓存内容:

 代码如下 复制代码

flush_all

4.最后退出telnet使用quit命令,再exit退出远程主机。

清除过期缓存

 

 代码如下 复制代码
/**
* Memcached的过期内存回收
*/
class mem_dtor extends Memcache
{
private $server_id;
public function __construct($host,$port)
{
$this->server_id = "$host:$port";
$this->connect($host,$port);
}
// 回收所有过期的内存
public function gc()
{
$t = time();
$_this = $this;
$func = function($key,$info) use ($t,$_this)
{
if($info[1] - $t delete($key);
}
};
$this->lists($func);
}
// 查看所有缓存内容的信息
public function info()
{
$t = time();
$func = function($key,$info) use ($t)
{
echo $key,' => Exp:',$info[1] - $t,"n"; //查看缓存对象的剩余过期时间
};
$this->lists($func);
}
private function lists($func)
{
$sid = $this->server_id;
$items = $this->getExtendedStats('items'); //获取memcached状态
foreach($items[$sid]['items'] as $slab_id => $slab) //获取指定server id 的 所有Slab
{
$item = $this->getExtendedStats('cachedump',$slab_id,0); //遍历所有Slab
foreach($item[$sid] as $key => $info) //获取Slab中缓存对象信息
{
$func($key,$info);
}
}
}
}
$mem = new mem_dtor('127.0.0.1',11211);
$mem->info();//查看状态
$mem->gc(); //回收

memcache缓存的批量删除方案

memcache默认只支持使用delete(key)和 flush_all,这两种方法都太极端了,不能满足用户的特定需求,如:批量删除‘aaaaaaaa_'开头的所有缓存,这个时候该怎么办?
1 getExtendStats 遍历所有item,删除指定的key(不推荐)
 网上有对应的php代码和perl程序,感兴趣的可以看看,在本地测试时可以使用,但是在真是服务器上请不要使用。
 

2 memcache结合DB


方法:每次set缓存时,将key值存入数据库,在要删除缓存时查询数据库,查询出对应的信息,在memcache中将其删除
 缺点:浪费数据裤磁盘
3 memcache伪命名空间(推荐)
memcache默认不提供命名空间,但可以设置一个全局变量,来模拟命名空间,代码如下:

 代码如下 复制代码

<?php  
//生成一个用来保存 namespace 的 key  
$ns_key = $memcache->get("foo_namespace_key");  
  
//如果 key 不存在,则创建,默认使用当前的时间戳作为标识
if($ns_key===false) $memcache->set("foo_namespace_key",time());  
  
//根据 namespace_key 生成真正的 key,确保是唯一的key值  
$my_key = "foo_".$ns_key.$otherParms; 


//然后利用拼接的my_key值设置你需要缓存的各种数据
$memcache->set($my_key,$value,false,expire); 


//或者key值获得以前存储的缓存
$memcaceh->get($my_key);
  
  
//需要删除整个 namespace 里的对象的时候,如:更改数据库或者删除某些信息后
//将ns_key的值改变,则以后在访问缓存时,以前时间的将永远不会别访问到,以此来实现批量删除缓存 
 $memcache->set("foo_namespace_key",time());
?>  

以上是个人见解,欢迎拍板

今天在一个朋友网站发现被加密码的php文件输出是乱码了,后来发现php使用了zend optimizer加密了,我们只要在机器上安装Zend Optimizer就可以了,我使用的是Directadmin,下面给大家介绍安装步骤。

一个客户反应网站乱码,使用了zend optimizer加密,检查了下vps发现没装zend optimizer,安装后即可解决乱码问题

 

 代码如下 复制代码
cd /usr/local/directadmin/custombuild/
vim ./options.conf

找到zend = no改成zend =yes,然后再执行./build zend,完成后会看到下面的提示

 代码如下 复制代码

 
[root@my2 custombuild]# ./build zend
File already exists:    ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
Zend Optimizer has been installed.

然后重启下apache即可

 代码如下 复制代码

 
[root@my2 ~]# php -v
PHP 5.2.17 (cli) (built: May 22 2012 02:47:56)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies

在php中采集数据最常用的就是使用curl函数来操作,因为curl函数是高性能并且多线程功能,下面我来介绍一个php采集程序,各位同学有需要可进入参考。

函数

 代码如下 复制代码

/**
 * 获取远程url的内容
 * @param string $url
 * @return string
 */
function get_url_content($url) {
  if(function_exists(curl_init)) {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
     
    $file_contents = curl_exec($ch);
    curl_close($ch);
  } else {
    $file_contents = file_get_contents($url);
  }
 
  return $file_contents;
}

调用方法

 代码如下 复制代码

$url = 'http://www.111cn.net';
$a = get_url_content($url);
echo $a;

上面只是一个简单的实例,如果我们想应用可参考我自己写的采集程序了。

1,获取目标网页数据;
2,截取相关内容;
3,写入数据库/生成HMTL文件;
下面就按照步骤来试试!
获取目标网页数据
1, 确定好,要获取的网页地址甚至形式,这里我们采用的网址是:/index.html?pageconfig=catalog_byproducttype&intProductTypeID=1&strStartChar=A&intResultsPage=1&tr=59
这个页面是有分页的,根据规律,我们找到只需要改变page参数就可以翻页!即:

我 们的网页形式是:/index.html?pageconfig=catalog_byproducttype& amp;intProductTypeID=1&strStartChar=A&intResultsPage= NUMBER &tr=59

红色部分是当前页码对应值!只需要改变该值就可以了!


2,获取页面内容:自然要用到PHP函数了!这里,两个函数都可以!他们分别是:


file_get_contents() 把整个文件读入一个字符串中。和 file() 一样,不同的是file_get_contents() 把文件读入一个字符串。file_get_contents() 函数是用于将文件的内容读入到一个字符串中的首选方法。如果操作系统支持,还会使用内存映射技术来增强性能。语法: file_get_contents( path , include_path , context , start , max_length ) curl() 了解详细,请参阅官网文档:http://cn.php.net/curl fopen()函数打开文件或者 URL。如果打开失败,本函数返回 FALSE。语法: fopen(filename,mode,include_path,context) 当然,我们采用的是第一个!其实,所有的都差不多,有兴趣的童子可以常识常识其他的!

 代码如下 复制代码

<?php
$oldcontent = file_get_contents(“http://www.abcam.cn/index.html?pageconfig=catalog_byproducttype&intProductTypeID=1&strStartChar=A&intResultsPage=2&tr=59”);
echo $oldcontent;
?>

运行PHP程序,上面的代码可以显示出整个网页!由于原网页采用的是绝地路径,所以现在显示的效果和原来的是一模一样的!
接下来就是要,截取内容了!截取内容的方法也有很多,今天介绍的一种比较简单:

 代码如下 复制代码
<?php
$oldcontent = file_get_contents(“http://www.abcam.cn/index.html?pageconfig=catalog_byproducttype&intProductTypeID=1&strStartChar=A&intResultsPage=2&tr=59″);
$oldcontent;
$pfirst = ‘<table border=”0″ cellspacing=”0″ cellpadding=”0″> <tr> <th style=”padding-left: 0px;”><p style=”font-size:12px”><strong>Code</strong></p></th>’;
$plast = ‘Goat polyclonal’;
$b= strpos($oldcontent,$pfirst);
$c= strpos($oldcontent,$plast);
echo substr($oldcontent,$b,$c-1);
?>

输出的,即为所需要的结果!
写入数据库和写入文件都是比较简单的!这里就写入文件了!

 代码如下 复制代码
<?php
$oldcontent = file_get_contents(“index.html?pageconfig=catalog_byproducttype&intProductTypeID=1&strStartChar=A&intResultsPage=2&tr=59″);
$oldcontent;
$pfirst = ‘<table border=”0″ cellspacing=”0″ cellpadding=”0″> <tr> <th style=”padding-left: 0px;”><p style=”font-size:12px”><strong>Code</strong></p></th>’;
$plast = ‘Goat polyclonal’;
$b= strpos($oldcontent,$pfirst);
$c= strpos($oldcontent,$plast);
$a = substr($oldcontent,$b,$c-1);
$file = date(‘YmdHis’).”.html”;
$fp = fopen($file,”w+”);
if(!is_writable($file)){
die(“File “.$file.” can not be written”);
}
else {
file_put_contents($file, $a);
echo “success”;
}
fclose($fp);
?>

OK,继续上班,今天的截取就到这里,下次就说说正则表达式提取内容

[!--infotagslink--]

相关文章

  • php语言实现redis的客户端

    php语言实现redis的客户端与服务端有一些区别了因为前面介绍过服务端了这里我们来介绍客户端吧,希望文章对各位有帮助。 为了更好的了解redis协议,我们用php来实现...2016-11-25
  • jQuery+jRange实现滑动选取数值范围特效

    有时我们在页面上需要选择数值范围,如购物时选取价格区间,购买主机时自主选取CPU,内存大小配置等,使用直观的滑块条直接选取想要的数值大小即可,无需手动输入数值,操作简单又方便。HTML首先载入jQuery库文件以及jRange相关...2015-03-15
  • JS实现的简洁纵向滑动菜单(滑动门)效果

    本文实例讲述了JS实现的简洁纵向滑动菜单(滑动门)效果。分享给大家供大家参考,具体如下:这是一款纵向布局的CSS+JavaScript滑动门代码,相当简洁的手法来实现,如果对颜色不满意,你可以试着自己修改CSS代码,这个滑动门将每一...2015-10-21
  • jQuery+slidereveal实现的面板滑动侧边展出效果

    我们借助一款jQuery插件:slidereveal.js,可以使用它控制面板左右侧滑出与隐藏等效果,项目地址:https://github.com/nnattawat/slideReveal。如何使用首先在页面中加载jquery库文件和slidereveal.js插件。复制代码 代码如...2015-03-15
  • PHP+jQuery翻板抽奖功能实现

    翻板抽奖的实现流程:前端页面提供6个方块,用数字1-6依次表示6个不同的方块,当抽奖者点击6个方块中的某一块时,方块翻转到背面,显示抽奖中奖信息。看似简单的一个操作过程,却包含着WEB技术的很多知识面,所以本文的读者应该熟...2015-10-21
  • SQLMAP结合Meterpreter实现注入渗透返回shell

    sqlmap 是一个自动SQL 射入工具。它是可胜任执行一个广泛的数据库管理系统后端指印, 检索遥远的DBMS 数据库等,下面我们来看一个学习例子。 自己搭建一个PHP+MYSQ...2016-11-25
  • php根据用户语言跳转相应网页

    当来访者浏览器语言是中文就进入中文版面,国外的用户默认浏览器不是中文的就跳转英文页面。 <&#63;php $lan = substr(&#8194;$HTTP_ACCEPT_LANGUAGE,0,5); if ($lan == "zh-cn") print("<meta http-equiv='refresh' c...2015-11-08
  • PHP实现今天是星期几的几种写法

    复制代码 代码如下: // 第一种写法 $da = date("w"); if( $da == "1" ){ echo "今天是星期一"; }else if( $da == "2" ){ echo "今天是星期二"; }else if( $da == "3" ){ echo "今天是星期三"; }else if( $da == "4"...2013-10-04
  • 腾讯视频怎么放到自己的网页上?

    腾讯视频怎么放到自己的网页上?这个问题是一个基本的问题,要把腾讯视频放到自己的网页有许多的办法,当然一般情况就是直接使用它们的网页代码了,如果你要下载资源再放到...2016-09-20
  • 原生js实现fadein 和 fadeout淡入淡出效果

    js里面设置DOM节点透明度的函数属性:filter= "alpha(opacity=" + value+ ")"(兼容ie)和opacity=value/100(兼容FF和GG)。 先来看看设置透明度的兼容性代码: 复制代码 代码如下: function setOpacity(ele, opacity) { if (...2014-06-07
  • 基于JavaScript实现网页倒计时自动跳转代码

    这篇文章主要介绍了基于JavaScript实现网页倒计时自动跳转代码 的相关资料,需要的朋友可以参考下...2015-12-29
  • 网页头部声明lang=”zh-cn”、lang=“zh”、lang=“zh-cmn-Hans”区别

    我们现在使用的软件都会自动在前面加一个申明了,那么在网页头部声明lang=”zh-cn”、lang=“zh”、lang=“zh-cmn-Hans”区别是什么呢?下面我们就一起来看看吧. 单...2016-09-20
  • Android中用HttpClient实现Http请求通信

    本文我们需要解决的问题是如何实现Http请求来实现通信,解决Android 2.3 版本以后无法使用Http请求问题,下面请看正文。 Android开发中使用HttpClient来开发Http程序...2016-09-20
  • mysql存储过程实现split示例

    复制代码 代码如下:call PROCEDURE_split('分享,代码,片段',',');select * from splittable;复制代码 代码如下:drop PROCEDURE if exists procedure_split;CREATE PROCEDURE `procedure_split`( inputstring varc...2014-05-31
  • C#实现Winform中打开网页页面的方法

    这篇文章主要介绍了C#实现Winform中打开网页页面的方法,涉及WinForm中WebBrowser的相关使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • PHP+Mysql+Ajax+JS实现省市区三级联动

    基本思想就是:在JS动态创建select控件的option,通过Ajax获取在PHP从SQL数据库获取的省市区信息,代码有点长,但很多都是类似的,例如JS中省、市、区获取方法类似,PHP中通过参数不同执行不同的select语句。index.html代码:复制...2014-05-31
  • JS实现程序暂停与继续功能代码解读

    下面代码用JS实现了程序的暂停与继续 复制代码 代码如下: <script type="text/javascript"> /*Javascript中暂停功能的实现 Javascript本身没有暂停功能(sleep不能使用)同时 vbscript也不能使用doEvents,故编写此函数实...2013-10-13
  • Go语言通过http抓取网页的方法

    这篇文章主要介绍了Go语言通过http抓取网页的方法,实例分析了Go语言通过http操作页面的技巧,需要的朋友可以参考下...2020-05-05
  • PHPCMS实现自动推送URL到百度站长平台

    我们一起来看一篇关于PHPCMS实现自动推送URL到百度站长平台,希望此教程能够帮助到各位朋友。 百度站长平台开放url推送接口,可以使用调用接口的形式主动及时推送u...2016-11-25
  • CSS+JS实现苹果cover flow效果示例

    cover flow效果就一个超级漂亮的图片切换效果了,下面我们来看看CSS+JS实现苹果cover flow效果示例吧,具体的操作步骤细节如下文介绍。 废话不多说, 直接上最终效果...2016-10-02