php函数 - 单位时间内字符串加密解密 19 September 2010 21:55 Sunday by 小屋 浏览(1939)

 

此函数可在指定时间内,加密还原字符串,超时无法还原。

用途如:单点登录的token加密传输,临时密码等等

 

 

<?php

/**

 * @param string $operation 操作(ENCODE | DECODE), 默认为 DECODE

 * @param string $key 密钥

 * @param int $expiry 密文有效期, 加密时候有效, 单位 秒,0 为永久有效

 * @return string 处理后的 原文或者 经过 base64_encode 处理后的密文

 *

 * @example

 *

 * $a = authcode('abc', 'E

阅读全文>>

magento添加随机商品模块 13 September 2010 8:50 Monday by小屋 浏览(2049)

以下代码在magento1.4.1.0中运行没有什么问题。将代码放在产品详细页的任何位置,如view.phtml或者media.phtml 中。

<!--for show other product-->
<?php $categories = $_product->getCategoryIds(); ?>
    <?php
        $result = array();
        foreach($categories as $cat_id) {
            $category = Mage::getModel('catalog/category');
            $category->load($cat_id);
            $collection = $category->getProductCollection();
            foreach ($collection as $product) {
                $result[] = $product->getId();
            }
 
        }
    ?>

    <div class="box-others-a

阅读全文>>

php利用crypt函数加密和解密 01 July 2010 17:48 Thursday by小屋 浏览(2598)

// +----------------------------------------------------------------------+
// | Wiki Framework |
// +----------------------------------------------------------------------+
// $string 明文 或 密文 必填
// $isEncrypt 是否加密 可选,默认为加密
// $key 密匙 可选,默认为空格
// $b = dencrypt($a,TRUE,'123'); 
// $c = dencrypt($b,false,'123');
// 采用SHA1生成密匙簿,超过300个字符使用ZLIB压缩
function dencrypt($string, $isEncrypt = true, $key = KEY_SPACE) {
    if (!isset($string{0}) || !isset($key{0})) {
        return false;
    }
    $dynKey = $isEncrypt ? hash('sha1', microtime(true)) : substr($string, 0, 40);
    $fixedKey = hash('sha1', $key);
    $dynKeyPart1 = substr($dynKey, 0, 20);
    $dynKeyPart2 = substr($dynKey, 20);
    $fixedKeyPart1 = substr($fixedKey, 0, 20);
    $fixedKeyPart2 = substr($fixedKey, 20

阅读全文>>

PHP文件缓存数据类 04 May 2010 22:30 Tuesday by小屋 浏览(2055)

点击查看