当前位置:首页 > PHP教程 > php函数 > 列表

php 用户验证 base64验证方法

发布:smiling 来源: PHP粉丝网  添加日期:2014-08-25 10:54:18 浏览: 评论:0 
  1. function dsetcookie($var, $value, $life = 0, $prefix = 1) { 
  2.  global $cookiedomain, $cookiepath, $addtime, $_server; 
  3.  setcookie($var, $value,$life ? $addtime + $life : 0, $cookiepath,$cookiedomain, $_server['server_port'] == 443 ? 1 : 0); 
  4. } 
  5.  
  6. function authcode($string, $operation = 'decode', $key = '', $expiry = 0) { 
  7.     global $webaddr; 
  8.     $auth_key=md5($webaddr); 
  9.  $ckey_length = 4; 
  10.  $key = md5($key ? $key : $auth_key); 
  11.  $keya = md5(substr($key, 0, 16)); 
  12.  $keyb = md5(substr($key, 16, 16)); 
  13.  $keyc = $ckey_length ? ($operation == 'decode' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : ''; 
  14.  $cryptkey = $keya.md5($keya.$keyc); 
  15.  $key_length = strlen($cryptkey); 
  16.  $string = $operation == 'decode' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string; 
  17.  $string_length = strlen($string); 
  18.  $result = ''; 
  19.  $box = range(0, 255); 
  20.  $rndkey = array(); 
  21.  for($i = 0; $i <= 255; $i++) { 
  22.   $rndkey[$i] = ord($cryptkey[$i % $key_length]); 
  23.  } 
  24.  for($j = $i = 0; $i < 256; $i++) { 
  25.   $j = ($j + $box[$i] + $rndkey[$i]) % 256; 
  26.   $tmp = $box[$i]; 
  27.   $box[$i] = $box[$j]; 
  28.   $box[$j] = $tmp; 
  29.  } 
  30.  for($a = $j = $i = 0; $i < $string_length; $i++) { 
  31.   $a = ($a + 1) % 256; 
  32.   $j = ($j + $box[$a]) % 256; 
  33.   $tmp = $box[$a]; 
  34.   $box[$a] = $box[$j]; 
  35.   $box[$j] = $tmp; 
  36.   $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); 
  37.  } 
  38.  if($operation == 'decode') { 
  39.   if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {//开源代码phpfensi.com 
  40.    return substr($result, 26); 
  41.   } else { 
  42.    return ''; 
  43.   } 
  44.  } else { 
  45.   return $keyc.str_replace('=', '', base64_encode($result)); 
  46.  } 
  47. } 

Tags: php用户验证 base64验证

分享到: