首页 > 代码库 > qq空间的g_tk算法

qq空间的g_tk算法

 1 function token(){ 2     $path = ‘cookie.txt‘;//cookie文件 3     if(file_exists($path)){ 4         $fp=fopen($path,"r"); 5         while(!(feof($fp))) 6         { 7          $text=fgets($fp); 8             if(preg_match("/(;)skey=(.*)(;)RK=/", $text, $matches)){ 9                 $str = trim($matches[2]);10                 break;11             }12         }13     }else{14         echo ‘cookie文件不存在‘;15         die();16     }17     $hash = 5381;18     for($i=0,$l=mb_strlen($str,‘utf-8‘);$i<$l;++$i){        19             $hash = $hash + uniord(mb_substr($str,$i,1,‘utf-8‘))+($hash<<5);20             21     }22     $g_tk = $hash&0x7fffffff;23     return $g_tk;24 }