|
|
我花了整天 都解决不到 akiz, 求求 各位大大 帮我 看看下 。 请指点 先谢啦。
2 个 PHP 文件
EncDec.php
- <?php
- class EncryptionsGKL{
-
- /*
- Simple Encrypt and Decrypt
- Written By Goh Keat Liang
- v0.1 initial release
- GPL v2.0 from community, to community
- */
-
-
- //settings for the encryption
- //private $encryption_mode = MCRYPT_MODE_ECB/CFB;
- private $encryption_mode = MCRYPT_MODE_CFB;
- private $cipher_algorithm = MCRYPT_RIJNDAEL_256;
- private $word = "genesis6";
- private $key = "";
- private $ivs = "";
- private $iv = "";
-
-
- function __construct(){
- $this->key = $this->hash($word);
- //echo $this->key;
- //create the cipher vector for the cookie
- //can tweek the vector size
- $this->ivs = mcrypt_get_iv_size($this->cipher_algorithm, $this->encryption_mode);
- $this->iv = mcrypt_create_iv($this->ivs, MCRYPT_DEV_URANDOM);
- }
-
-
- private function hash($word){
- return md5($word);
- }
-
- public function descrypt($text_to_decrypt){
- return mcrypt_decrypt($this->cipher_algorithm, $this->key, hexdec($text_to_decrypt), $this->encryption_mode, $this->iv);
- }
-
- public function encrypt($text_to_encrypt){
- return mcrypt_encrypt($this->cipher_algorithm, $this->key, $text_to_encrypt, $this->encryption_mode, $this->iv);
- }
-
-
- }
-
- /*$testE = new EncryptionsGKL();
- echo $cipher_ = $testE->encrypt("keatliang");
- echo $testE->descrypt($cipher_);*/
- ?>
复制代码
cookie.php
- <?
- /*
- Simple Cookie Lib with simple Encryption
- Written by Goh Keat Liang
- v0.1 initial release
- GPL v2.0 from community, to community
- */
- include 'EncDec.php';
-
- //add a list of cookie you wanted
- class COOKIE{
- public static $USER_ID = "UID";
- }
-
- class CookieGKL extends EncryptionsGKL{
-
- private $numExpiredTime = "";
- private $strCookiePath = "";
- private $strDomain = "";
-
-
- function __construct($numExpiredTime,$strCookiePath,$strDomain){
- parent::__construct();
- $this->numExpiredTime = $numExpiredTime;
- $this->strCookiePath = $strCookiePath;
- $this->strDomain = $strDomain;
- }
-
-
- public function setCookie($cookieName,$cookieValue){
- $cookieValue = $this->encrypt($cookieValue);
- setcookie($cookieName,
- $cookieValue,
- $this->numExpiredTime,
- $this->strCookiePath,
- $this->strDomain
- );
- }
-
- public function getCookie($cookieName){
- $cookieCryptedValue = $_COOKIE[$cookieName];
- return $this->descrypt($cookieCryptedValue);
- }
-
- public function destroyCookies(){
- }
-
- public function removeCookie(){
- }
- }
-
- $testC = new CookieGKL(time()+3600,"/","genesissix.com",1);
-
- $testC->setCookie(COOKIE::$USER_ID, 'keatliang');
- echo $testC->getCookie(COOKIE::$USER_ID);
- ?>
复制代码 |
|