php ascii移位加密,php COOKIE加密函数 (按位求ascii编码 乘key)

[php]代码库define ("DOMAIN", "54dev.com");

define ("PATH", "/");

define ("COOKIEID", "encodeCookie");

define ("COOKIEKEY", "raz"); // max 5 chars is good

/**

* class encodeCookie

*

* encode cookies before you send them

*

*/

class encodeCookie {

/**

* encodeCookie::$config

*

* configuration

*

*/

var $config;

/**

* encodeCookie::encodeCookie()

*

* constructor

*

*/

function encodeCookie () {

$this->config = array ();

$this->config['cookie_key'] = COOKIEKEY;

$this->config['cookie'] = array (

'cookie_id' => COOKIEID,

'cookie_path' => PATH,

'cookie_domain' => DOMAIN,

);

}

/**

* encodeCookie::set_Cookie()

*

* sets the cookie

*

* @param string $value

* @param integer $sticky

*/

function set_Cookie ($name, $value = "", $sticky = 0) {

$exipres = "";

if ($sticky == 1) {

$expires = time() + 60*60*24*365;

}

$name = $this->config['cookie']['cookie_id'].$name;

$newValue = $this->encodeC ($value);

@setcookie($name, urlencode($newValue), $expires, $this->config['cookie']['cookie_path'], $this->config['cookie']['cookie_domain']);

}

/**

* encodeCookie::get_Cookie()

*

* gets the cookie

*

*/

function get_Cookie ($name) {

if ( isset( $_COOKIE[$this->config['cookie']['cookie_id'].$name] ) ) {

$cookie = urldecode ( $_COOKIE[$this->config['cookie']['cookie_id'].$name] );

return $this->decodeC ($cookie);

} else {

return FALSE;

}

}

/**

* encodeCookie::encodeC()

*

* encodes the cookie

*

*/

function encodeC ($cookie) {

$newcookie = array ();

$cookie = base64_encode ($cookie);

for ( $i=0; $i<=strlen ($cookie); $i++ ) {

$newcookie[ $i ] = ord ( $cookie[ $i ] ) * $this->encodeKey ();

}

$newcookie = implode ('.', $newcookie);

return $newcookie;

}

/**

* encodeCookie::decodeC()

*

* decodes the cookie

*

*/

function decodeC ($oldcookie) {

$newcookie = array ();

$cookie = explode ('.', $oldcookie);

for ( $i=0; $i<=strlen ($oldcookie); $i++ ) {

$newcookie[ $i ] = chr ( $cookie[ $i ] / $this->encodeKey () );

}

$newcookie = implode ('', $newcookie);

$newcookie = base64_decode ($newcookie);

return $newcookie;

}

/**

* encodeCookie::encodeKey()

*

* encodes the key

*

*/

function encodeKey () {

$newkey = 0;

for ( $i=0; $i<=strlen ( $this->config['cookie_key'] ); $i++ ) {

$newkey += ord ( $this->config['cookie_key'][ $i ] );

}

return $newkey;

}

}

694748ed64b9390909c0d88230893790.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值