php 模仿用户登陆读取DZ 论坛验码程序

error_reporting(0);
session_start();
require("config.php");
if(!is_dir("temp"))
{
 mkdir("temp",0777);
}
$c=tempnam("temp","c");
$url=DZ."logging.php?action=login";
 $ch=curl_init();
 curl_setopt($ch,CURLOPT_URL,$url);
 curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);
 curl_setopt($ch,CURLOPT_COOKIEJAR,$c);
 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
 $html=curl_exec($ch);
 preg_match("/(?<=charset=).*?(?=")/",$html,$charset);
 if($charset[0]!=="utf-8")
 {
  $html=iconv($charset[0],"utf-8",$html);
 }
 curl_close($ch);
 preg_match("/(?<=formhash" value=").*?(?=")/",$html,$outs);
 $_SESSION["hash"]=$outs[0];
 

阅读全文

PHP生成扭曲有角度支持中文的图片验证码函数

PHP生成扭曲有角度支持中文的图片验证码函数

<?php
function make_rand($length="32"){//验证码文字生成函数
$str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
$result="";
for($i=0;$i<$length;$i++){
$num[$i]=rand(0,61);
$result.=$str[$num[$i]];
}
return $result;
}
$checkcode = make_rand(5);
$im_x=160;
$im_y=32;
function make_crand($length="5") {
$string = ;
for($i=0;$i<$length;$i++) {
$string .= chr(rand(0xB0,0xF7)).chr(rand(0xA1,0xFE));
}
return $string;
}
function getAuthImage($text , $im_x = 230 , $im_y = 32) {
$im = imagecreatetruecolor($im_x,$im_y);
$text_c = ImageColorAllocate($im, mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));
$tmpC0=mt_rand(100,255);
$tmpC1=mt_rand(100,255);
$tmpC2=mt_rand(100,255);
$buttum_c = ImageColorAllocate($im,$tmpC0,$tmpC1,$tmpC2);
imagefill($im, 16, 13, $buttum_c);
//echo $text;
$font = c:WINDOWSFontssimsun.ttc;
//echo strlen($text);

阅读全文

php实现多线程

php实现多线程
服务器发送多个请求要实现多进程要方便很多。只能使用在cli模式。可以用在特殊场合,如邮件发送任务等。
资源的共享访问使用了文件锁,并不是很可靠,主要是为了能够在Windwos下使用,如果确实有必要可以考虑自己改用相应的信号灯机制(这个扩展只能用于xUNIX)。

阅读全文

php 用txt文本文件做数据库程序

define ("tblPath",".");
define ("exten",".php");
define ("fileHead","<? echo "You are wellcome!"?".">This file only for class txtTbl");
class txtTbl {
  var $innerName="";  //php名称
  var $innerCount;  //数据库记录数目
  var $innerFields;  //数据库字段列表数组
  var $inner_F_Count; //数据库字段数目
  var $fullName;  //完整的文件名
  var $isModify = false;  //当前记录是否被修改
  var $fileModify = false;  //数据库是否被修改
  var $innerRecorders;  //数据库记录数组
  var $curLine;  //当前记录号
  var $curArray;  //当前行数组
  var $stringDel;  //保存被删除记录
  var $sprt1;  //数据库记录间的分隔符
  var $sprt2;  //数据库字段间的分隔符
  var $innerBof = true;
  var $innerEof = false;

阅读全文

php 防google 分页效果代码

function getPageRange($currentPage, $totalPages, $displaySize = 10) {
    if ($totalPages <= 0 || $displaySize <= 0) {
        return array();
    } elseif ($displaySize > $totalPages) {
        $startPage = 1;
        $endPage = $totalPages;
    } else {
        if ($currentPage % $displaySize === 0) {
            $startPage = $currentPage - $displaySize + 1;
        } else {
            while (($currentPage % $displaySize)) {
                --$currentPage;
            }
            $startPage = $currentPage + 1;
        }
        if ($startPage <= 0) {
            $startPage = 1;
        }
        $endPage = $startPage + $displaySize - 1;
        if ($endPage > $totalPages) {
            $endPage = $totalPages;
            $startPage = $endPage - $displaySize + 1;
        }
    }
    return range($startPage, $endPage);
}php?name=%BA%AF%CA%FD>函数getPageRange接受三个参数,当前页$currentPage,总页数$totalPages,和翻页区间长度$displaySize,默认是10。根据这三个参数,函数getPageRange会生成一个适当的包含了$currentPage的翻页区间。首先,我们需要排除非法的参数值,对于总页数或区间长度小于零的情况,须加以检查。

然后,我们考察静态划分的思路。如前所述,给定翻页区间长度后,便可用总页数除以长度,得到区间个数。与此同时,我们可分析得知并不是所有区间都含有相同的页数,在极端情况下,还会出现总页数小于给定的翻页区间长度,那么划分或切割的结果将永远只有一个区间。幸运的是,这不会给我们的核心算法带来什么干扰,但我们仍须重视代码的健壮性。所以,我们先考虑极端情况,在运用算法解决核心问题之前,先迅速捕捉只有一页的区间。

接下来,我们便可以看看区间的固有属性了。每个动态切割的区间,都有一个起始页和一个尾页;由于区间彼此存在先后顺序,所以在经过静态划分后,我们始终会得到第一个(首)区间和最后一个(尾)区间,若首尾区间重合,则说明总页数小于给定的翻页区间长度。无论如何,算法需要解决的关键问题是如何找到区间的起始页和尾页,一旦确定这两个元素,便可以使用PHP内置的range函数生成区间内的全部页码。

算法利用当前页$currentPage和翻页区间长度$displaySize做比较,来判断当前页在区间内所处的位置,进而推导出区间起始页和尾页与当前页的偏移量。为了做到完美无缺,我们还要考虑边界溢出的问题,这也非常简单,只需判断起始页和尾页是否介于1和总页数之间即可。

至此,对于代码的分析已经完成。我们来看一下算法的时间效率,通俗地说,算法中的基本操作是求模,算法的执行时间取决于$currentPage与$displaySize的差值,差值越大,则求模次数越多、执行时间越长,呈线性结构。而实际的执行结果则是在瞬间完成的。

下面,我们来结合上面的Google搜索结果页,利用getPageRange函数生成一个翻页区间,输入所需参数:
print_r(implode(,, getPageRange(18, 27, 20)));得到的结果是:
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20大家会发现这和Google搜索结果页显示的完全不一样。对,因为Google的翻页区间把当前页强制设置在中间位置上了!嗯,不要灰心,我们仍可以利用getPageRange函数得到与之相匹配的结果,只需把问题再分解一下:
print_r(implode(,, array_merge(getPageRange(17, 17, 10), getPageRange(27, 27, 10))));得到的结果是:
8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27

阅读全文

php 导入csv数据到mysql数据库

class Import{

 var $csv_fields=array(); //fields in csv to care about...
 var $csv_file; //file to open
 var $csv_data; //data in file
 var $csv_array = array(); //array of data in file
 var $csv_all_fields = array(); //all the field names in the csv file
 var $csv_data_all = array(); //all the data
 var $csv_data_keyed = array(); //all the data
 var $tmp_array=array();
 var $mysql_array=array();
 var $table; //table to insert into
 var $mysql_link; //database
 var $instructions=array(); //sql and default settings
 var $instruct_functions = array(); //function calls
 var $debug=0; // show debug information - step by step messages
 var $return_debug=0; // return debug information instead of echoing it
 var $vals_per_insert=100; //number of values to add per insert statement of SQL
 var $format="linux";
 var $linebreak_char="n";
 var $delimit_char = ",";
 var $use_external_csv_header_file = 0;
 var $external_headers="";
 
 function Import(){
  echo "n";
  return(TRUE);
 }

阅读全文

php 导入数据到excel

class CsvFieldDump  {

 var $headers;
 var $fieldnum;
 function CsvFieldDump($infile){
  if(empty($infile)){
   die("You must specify a csv file to readn");
  }
  if(!file_exists($infile)){
   die("$infile doesnt exist!n");
  }
  $this->infile  = $infile;
  $this->fieldnum = $field;
  $this->createFile=0;
  return(true);
 }

阅读全文

php array_push 向数组增加值函数

php  array_push 向数组增加值函数
 public static function insert(&$array, $key, $newValue, $before = true) {
  $result = false;
  $size = sizeof($array);
  for ($i=0; $i<$size; $i++) {
   $value = array_shift($array);
   if ($i==$key) {
    if ($before) {
     array_push($array, $newValue);
     array_push($array, $value);
    } else {
     array_push($array, $value);
     array_push($array, $newValue);
    }
    $result = true;
   } else {
    array_push($array, $value);
   }
  }
  if (!$result) {
   array_push($array, $newValue);
  }
  return;
 }

阅读全文

Memcache 中实现消息队列


class Memcache_Queue
{
private $memcache;
private $name;
private $prefix;
function __construct($maxSize, $name, $memcache, $prefix = "__memcache_queue__")
{
if ($memcache == null) {
throw new Exception("memcache object is null, new the object first.");
}
$this->memcache = $memcache;
$this->name = $name;
$this->prefix = $prefix;
$this->maxSize = $maxSize;
$this->front = 0;
$this->real = 0;
$this->size = 0;
}
function __get($name)
{
return $this->get($name);
}
function __set($name, $value)
{
$this->add($name, $value);
return $this;
}
function isEmpty()
{
return $this->size == 0;
}
function isFull()
{
return $this->size == $this->maxSize;
}
function enQueue($data)
{
if ($this->isFull()) {
throw new Exception("Queue is Full");
}
$this->increment("size");
$this->set($this->real, $data);
$this->set("real", ($this->real + 1) % $this->maxSize);
return $this;
}
function deQueue()
{
if ($this->isEmpty()) {
throw new Exception("Queue is Empty");
}
$this->decrement("size");
$this->delete($this->front);
$this->set("front", ($this->front + 1) % $this->maxSize);
return $this;
}
function getTop()
{
return $this->get($this->front);
}
function getAll()
{
return $this->getPage();
}
function getPage($offset = 0, $limit = 0)
{
if ($this->isEmpty() || $this->size < $offset) {
return null;
}
$keys[] = $this->getKeyByPos(($this->front + $offset) % $this->maxSize);
$num = 1;
for ($pos = ($this->front + $offset + 1) % $this->maxSize; $pos != $this->real; $pos = ($pos + 1) % $this->maxSize)
{
$keys[] = $this->getKeyByPos($pos);
$num++;
if ($limit > 0 && $limit == $num) {
break;
}
}
return array_values($this->memcache->get($keys));
}
function makeEmpty()
{
$keys = $this->getAllKeys();
foreach ($keys as $value) {
$this->delete($value);
}
$this->delete("real");
$this->delete("front");
$this->delete("size");
$this->delete("maxSize");
}
private function getAllKeys()
{
if ($this->isEmpty())
{
return array();
}
$keys[] = $this->getKeyByPos($this->front);
for ($pos = ($this->front + 1) % $this->maxSize; $pos != $this->real; $pos = ($pos + 1) % $this->maxSize)
{
$keys[] = $this->getKeyByPos($pos);
}
return $keys;
}
private function add($pos, $data)
{
$this->memcache->add($this->getKeyByPos($pos), $data);
return $this;
}
private function increment($pos)
{
return $this->memcache->increment($this->getKeyByPos($pos));
}
private function decrement($pos)
{
$this->memcache->decrement($this->getKeyByPos($pos));
}
private function set($pos, $data)
{
$this->memcache->set($this->getKeyByPos($pos), $data);
return $this;
}
private function get($pos)
{
return $this->memcache->get($this->getKeyByPos($pos));
}
private function delete($pos)
{
return $this->memcache->delete($this->getKeyByPos($pos));
}
private function getKeyByPos($pos)
{
return $this->prefix . $this->name . $pos;
}
}

阅读全文