一段三年前的源码

诚信通代购源码。 本源码仅供技术交流,若无意中侵犯到您的权利请发邮件至jiansihun#foxmail.com,请看到源码之后修正源码使用漏洞。

此源码仅是作者无意中于2007年练习写出,仅仅是一个demo而已。

 

 

代码使用方法:

请替换代码中用户名称和密码

该源码已经不再更新。

源码下载

Share
Posted in php at June 27th, 2010. No Comments.

php数组的插入

1
2
3
4
function array_insert(&$input, $offset, $replacement){
   array_splice($input, $offset, 0, 0);
   $input[$offset] = $replacement;
  }

当然也可以有另外一种写法。

1
2
3
function array_insert(&$array,$pos,$val){
   array_splice($array,$pos,0,array($val));
}

还有另外一种,把数组切分之后,用array_merge合并起来,这种写法就很蠢了,不写了。

Share
Posted in php at March 13th, 2010. No Comments.

xxtea的php算法实现

<?php
/* XXTEA encryption arithmetic library.
 *
 * Copyright (C) 2006 Ma Bingyao <andot@ujn.edu.cn>
 * Version:      1.5
 * LastModified: Dec 5, 2006
 * This library is free.  You can redistribute it and/or modify it.
 */

function long2str($v, $w) {
    $len = count($v);
    $n = ($len – 1) << 2;
    if ($w) {
        $m = $v[$len - 1];
        if (($m < $n – 3) || ($m > $n)) return false;
        $n = $m;
    }
    $s = array();
    for ($i = 0; $i < $len; $i++) {
        $s[$i] = pack("V", $v[$i]);
    }
    if ($w) {
        return substr(join('', $s), 0, $n);
    }
    else {
        return join('', $s);
    }
}
 
function str2long($s, $w) {
    $v = unpack("V*", $s. str_repeat("", (4 – strlen($s) % 4) & 3));
    $v = array_values($v);
    if ($w) {
        $v[count($v)] = strlen($s);
    }
    return $v;
}

function int32($n) {
    while ($n >= 2147483648) $n -= 4294967296;
    while ($n <= -2147483649) $n += 4294967296;
    return (int)$n;
}

function xxtea_encrypt($str, $key) {
    if ($str == "") {
        return "";
    }
    $v = str2long($str, true);
    $k = str2long($key, false);
    if (count($k) < 4) {
        for ($i = count($k); $i < 4; $i++) {
            $k[$i] = 0;
        }
    }
    $n = count($v) – 1;

    $z = $v[$n];
    $y = $v[0];
    $delta = 0x9E3779B9;
    $q = floor(6 + 52 / ($n + 1));
    $sum = 0;
    while (0 < $q–) {
        $sum = int32($sum + $delta);
        $e = $sum >> 2 & 3;
        for ($p = 0; $p < $n; $p++) {
            $y = $v[$p + 1];
            $mx = int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
            $z = $v[$p] = int32($v[$p] + $mx);
        }
        $y = $v[0];
        $mx = int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
        $z = $v[$n] = int32($v[$n] + $mx);
    }
    return long2str($v, false);
}

function xxtea_decrypt($str, $key) {
    if ($str == "") {
        return "";
    }
    $v = str2long($str, false);
    $k = str2long($key, false);
    if (count($k) < 4) {
        for ($i = count($k); $i < 4; $i++) {
            $k[$i] = 0;
        }
    }
    $n = count($v) – 1;

    $z = $v[$n];
    $y = $v[0];
    $delta = 0x9E3779B9;
    $q = floor(6 + 52 / ($n + 1));
    $sum = int32($q * $delta);
    while ($sum != 0) {
        $e = $sum >> 2 & 3;
        for ($p = $n; $p > 0; $p–) {
            $z = $v[$p - 1];
            $mx = int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
            $y = $v[$p] = int32($v[$p] – $mx);
        }
        $z = $v[$n];
        $mx = int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
        $y = $v[0] = int32($v[0] – $mx);
        $sum = int32($sum – $delta);
    }
    return long2str($v, true);
}
?>

Share
Posted in php at February 7th, 2010. 3 Comments.

php重载的一个用法

     在php中,实现了变量的get和set方法的重载,在5.1.0之后又实现了两个方法的重载,分别为__isset()和__unset()。注意这些方法不能被声明为static方法。

     而在方法的重载上提供了__call(string name, array arguments )函数,该函数将会返回被执行方法的返回值,其调用是在函数在该类中未被找到之后。

     可能这么讲比较抽象,更直观的方式是,我们找一个实际中的应用。在java之中,会经常使用到setter和getter方式。比如,setData() 就是设置一个data变量的值来实现。那么在php中我们可以这么做。我们可能需要设置一个类似存储器的东西,来管理我们放置类中的所有变量。那么我们可以这么实现。

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 public function __call($method, $args)
    {
        switch (substr($method, 0, 3)) {
            case 'get' :
 
                $key = $this-&gt;_underscore(substr($method,3));
                $data = $this-&gt;getData($key, isset($args[0]) ? $args[0] : null);

            case 'set' :


                $key = $this-&gt;_underscore(substr($method,3));
                $result = $this-&gt;setData($key, isset($args[0]) ? $args[0] : null);
                return $result;

        }
    }

       事实上在那么可以很轻易的把一些关键数据放置于data之中。甚至在你需要的缓存它们。

Share
Posted in php at February 5th, 2010. No Comments.