迅速学会PHP加密解密技巧
闲话少说,先将它们打包成一个文件就叫fun.php吧
< ?php
function passport_encrypt($txt, $key) {
srand((double)microtime() * 1000000);
$encrypt_key = md5(rand(0, 32000));
$ctr = 0;
$tmp = '';
for($i = 0;$i < strlen($txt); $i++) {
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
$tmp .= $encrypt_key[$ctr].($txt[$i]
^ $encrypt_key[$ctr++]);
}
return base64_encode(passport_key($tmp, $key));
}
function passport_decrypt($txt, $key) {
$txt = passport_key(base64_decode($txt), $key);
$tmp = '';
for($i = 0;$i < strlen($txt); $i++) {
$md5 = $txt[$i];
$tmp .= $txt[++$i] ^ $md5;
}
return $tmp;
}
function passport_key($txt, $encrypt_key) {
$encrypt_key = md5($encrypt_key);
$ctr = 0;
$tmp = '';
for($i = 0; $i < strlen($txt); $i++) {
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
$tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
}
return $tmp;
}
?>
以下是一些示例…加深对这三个PHP加密解密函数的理解…
//string.php < ?php include “fun.php”; $txt = “This is a test”; $key = “testkey”; $encrypt = passport_encrypt($txt,$key); $decrypt = passport_decrypt($encrypt,$key); echo $txt.”< br>< hr>”;
相关文档:
<?
class upload{
private $name; //$_FILES['file'][name]
private $type; //$_FILES['file'][type]
privat ......
看yii框架源码的时候,发现了
ReflectionClass这个方法,才发现原来是php5的新东西,于是稍微研究了下。php的反射api一共有:
class
Reflection
{ }
interface Reflector
{ }
class
ReflectionException
extends
Exception
{ }
class
Re ......
In the directory where you plan to install Elgg, do the following:
Create the file .htaccess and add these two lines
RewriteEngine on
RewriteRule ^testing.php$ modrewrite.php
This tells the webserver to load modrewrite.php when testing.php is
requested.
In order to get this test to work on ......
Output Control
函数可以让你自由控制脚本中数据的输出。它非常地有用,特别是对于:当你想在数据已经输出后,再输出文件头的情况。输出控制函数不对使用
header()
或
setcookie(),
发送的文件头信息产生影响
,
只对那些类似于
echo()
和
PHP
代码的数据块有作用。
我们先举一个简单的例子,让大家对 ......
xml_parse解析xml文件时候,
很有可能不仅仅调用一次character_handler。
所以在获得xml节点的文本信息的时候,要用连接运算".="。
参考 http://jp2.php.net/manual/ro/function.xml-set-character-data-handler.php
ken at positive-edge dot com
30-Jan-2002
01:20
the function handler is called ......