PHP加密解密内部算法
http://www.dedecms.com/knowledge/program/php/2009/0929/51.html
来源:PHP100 作者:PHP100er 发表于:2009-09-29 11:05 点击:
2363
最近学习URL跳转的时候新进三个超好用的PHP加密解密函数,貌似是discuz里的使用这些加密解密的原因是因为有时自己的URL地址被人获取以后想破解你里面传值的内容就必须知道你的key,没有key,他应该要破了一阵子才能知道你URL里面的内容吧... 闲话少说,先将它
最近学习URL跳转的时候新进三个超好用的PHP加密解密函数,貌似是discuz里的…使用这些加密解密的原因是因为有时自己的URL地址被人获取以后想破解你里面传值的内容就必须知道你的key,没有key,他应该要破了一阵子才能知道你URL里面的内容吧...
闲话少说,先将它们打包成一个文件就叫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;
}
?>
以下是一些示例…加深对这三个加密解密函数的理解…
//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>”;
echo $encrypt.”<br><hr>”;
echo $decrypt.”<br><hr>”;
?>
//array.php
<?php
include “fun.php”;
$array = array(
"a" => "1",
相关文档:
向mysql写入数据时,如:mysql_query("update tableName set `title`='goaler's blog'");
这个时候,PHP将会报错,ASP中处理时也一样。
因为数据库对单引号过敏。
ASP中需要进行replace("'","''",str);
而PHP中则可以直接使用addslashes。
ASP问题这里暂不考虑,本文要说的是PHP相关的strip ......
使用Thrift来让PHP操作Cassandra无疑是一个首选方案,但是配置和操作比较麻烦。
我们可以使用一个php的模块phpcassa来操作Cassandra。
我们先插入一些数据:
下载phpcassa:http://github.com/downloads/hoan/phpcassa/phpcassa-0.1.zip
解压缩,放到项目的include目录下。
写一个php文件,内容如下:
......
第一步 安装MySQL
[root@localhost usr]# groupadd mysql
[root@localhost usr]# useradd -g mysql mysql
[root@localhost usr]# cd /usr/local
[root@localhost local]# tar -zxvf mysql-5.0.51.tar.gz
[root@localhost local]# cd mysql-5.0.51
[root@localhost mysql-5.0.51# ./configure --prefix=/usr/local/my ......
一个非常简单的PHP生成缩略图的代码程序,参数及代码都算得上精简,有兴趣的朋友可以试下它的功能,有不太完善的地方还请指正。 非原创,来自网络
<?$FILENAME="image_name";
// 生成图片的宽度
$RESIZEWIDTH=400;
// 生成图片的高度
$RESIZEHEIGHT=400;
function ResizeImage($im,$maxwidth,$maxheight,$name){ ......
VC6是什么?
VC6就是legacy Visual
Studio 6 compiler,就是使用这个编译器编译的
VC9是什么?
VC9就是the Visual Studio
2008 compiler,就是用微软的VS编辑器编译的
那我们如何选择下载哪个版本的PHP呢?
如果你是在windows下
使用Apache+PHP的,请选择VC6版本;
如果你是在windows下使用IIS+PHP的,请选择VC9 ......