| 自己网站整合了一个DZ的论坛,用户同步现在实现的是新增网站用户的同时,向ucenter里插入一条用户记录, 同步登陆是网站登录的同时,写一个DZ的cookie
 但现在不行,不知道是加密算法不对,还是哪里有错
 下面是我从DZ里面抠出来的,设置cookie的方法,大家帮忙看看哪里有问题:
 
 
 <?php
 $cookiepre = 'dz_';   // cookie 前缀
 $cookiedomain = '';   // cookie 作用域
 $cookiepath = '/';    // cookie 作用路径
 $timestamp = time();
 
 function dare_dsetcookie($var, $value = '', $life = 0, $prefix = 1, $httponly = false) {
 global $cookiepre, $cookiedomain, $cookiepath, $timestamp;
 //$_G['cookie'][$var] = $value;
 $var = ($prefix ? $cookiepre : '').$var;
 $_COOKIE[$var] = $var;
 if($value == '' || $life < 0) {
 $value = '';
 $life = -1;
 }
 $httponly = false;
 
 $life = $life > 0 ? $timestamp + $life : ($life < 0 ? $timestamp - 31536000 : 0);
 $path = $httponly && PHP_VERSION < '5.2.0' ? $cookiepath.'; HttpOnly' : $cookiepath;
 
 $secure = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
 if(PHP_VERSION < '5.2.0') {
 setcookie($var, $value, $life, $path, $cookiedomain, $secure);
 } else {
 setcookie($var, $value, $life, $path, $cookiedomain, $secure, $httponly);
 }
 }
 function dare_authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
 return dare_uc_authcode($string, $operation, $key, $expiry);
 }
 
 function dare_uc_authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
 $ckey_length = 4;
 $key = md5($key ? $key : UC_KEY);
 $keya = md5(substr($key, 0, 16));
 $keyb = md5(substr($key, 16, 16));
 $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
 
 $cryptkey = $keya.md5($keya.$keyc);
 $key_length = strlen($cryptkey);
 
 $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
 $string_length = strlen($string);
 
 $result = '';
 $box = range(0, 255);
 
 $rndkey = array();
 for($i = 0; $i <= 255; $i++) {
 $rndkey[$i] = ord($cryptkey[$i % $key_length]);
 }
 
 for($j = $i = 0; $i < 256; $i++) {
 $j = ($j + $box[$i] + $rndkey[$i]) % 256;
 $tmp = $box[$i];
 $box[$i] = $box[$j];
 $box[$j] = $tmp;
 }
 
 for($a = $j = $i = 0; $i < $string_length; $i++) {
 $a = ($a + 1) % 256;
 $j = ($j + $box[$a]) % 256;
 $tmp = $box[$a];
 $box[$a] = $box[$j];
 $box[$j] = $tmp;
 $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
 }
 
 if($operation == 'DECODE') {
 if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
 return substr($result, 26);
 } else {
 return '';
 }
 } else {
 return $keyc.str_replace('=', '', base64_encode($result));
 }
 }
 
 function dare_synlogin($uid) {
 global $_SGLOBAL;
 header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
 $cookietime = 31536000;
 $uid = intval($uid);
 $query = $_SGLOBAL['bbsdb']->query("SELECT uid, username, password FROM pre_common_member WHERE uid='".$uid."' limit 1");
 $member = $_SGLOBAL['bbsdb']->fetch_array($query);
 dare_dsetcookie('auth', dare_authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);
 }
 function dare_synlogout($get, $post) {
 header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
 dare_dsetcookie('auth', '', -31536000);
 }
 
 function dare_readCookie(){
 $arr = explode("\t", dare_authcode(dare_getCookie('auth'), 'DECODE'));
 return $arr;
 }
 
 function dare_getCookie($cookieName) {
 global $cookiepre;
 if(isset($_COOKIE[$cookiepre.$cookieName]))
 return $_COOKIE[$cookiepre.$cookieName];
 else
 return "";
 }
 ?>
 
 
 |