checkModuleSession.php
资源名称:BBWPS.rar [点击查看]
上传用户:yttaitong
上传日期:2009-05-10
资源大小:128k
文件大小:8k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
PHP
- <?php
- /*
- [BBWPS!] (C)2006-2010 小蜜蜂版权所有.
- This is NOT a freeware, use is subject to license terms
- 时间:2007年12月
- 描述:检查用户是否登录
- */
- function checkCookie(){
- global $baseCheckCode,$_COOKIE,$basePath,$_GET;
- if(!$_COOKIE['bbwps_user']||!$_COOKIE['bbwps_pwd']||!$_COOKIE['bbwps_ip']||!$_COOKIE['bbwps_check']){
- if(!$_GET['bbwps_user']||!$_GET['bbwps_pwd']||!$_GET['bbwps_ip']||!$_GET['bbwps_check']){
- ExeSuccess("您还没有登陆",$basePath);
- }
- else {
- extract($_GET);
- }
- }
- else {
- extract($_COOKIE);
- }
- $checkPass = decoded($bbwps_check,$baseCheckCode);
- $loginArray = array("bbwps_user"=>$bbwps_user,"bbwps_regctrl"=>$bbwps_regctrl,"bbwps_permit"=>$bbwps_permit);
- if($checkPass==$bbwps_pwd)
- return($loginArray);
- else ExeSuccess("您还没有登陆",$basePath);
- }
- function encode_key($txt, $encrypt_key) {
- $encrypt_key = md5($encrypt_key);
- $ctr = 0;
- $tmp = '';
- for($i = 0; $i < strlen($txt); $i++) {
- $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
- $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
- }
- return $tmp;
- }
- function decoded($codeString,$key){
- $txt = $codeString;
- $txt = encode_key(base64_decode($txt), $key);
- $tmp = '';
- for($i = 0;$i < strlen($txt); $i++) {
- $md5 = $txt[$i];
- $tmp .= $txt[++$i] ^ $md5;
- }
- return $tmp;
- }
- function encode($codeString,$key){
- $txt = $codeString;
- srand((double)microtime() * 1000000);
- $encrypt_key = md5(rand(0, 32000));
- $ctr = 0;
- $tmp = '';
- for($i = 0;$i < strlen($txt); $i++) {
- $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
- $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
- }
- return base64_encode(encode_key($tmp, $key));
- }
- function isLogin($path){
- global $installPath,$host,$basePath;
- if(!$path) return null;
- $popedom="http://".$host.$installPath."/";
- $_bbwspSession=getBBWPSSession($path);
- if(count($_bbwspSession)>0){
- $checkpopedomNum=substr($_bbwspSession["BBWPS_MODULE_POPEDOM"],-1);
- $checkpopedom=MakeMd5($popedom,$checkpopedomNum).$checkpopedomNum;
- if($checkpopedom==$_bbwspSession["BBWPS_MODULE_POPEDOM"]){
- return $_bbwspSession["BBWPS_MODULE_USERNAME"];
- }
- else{
- echo "<script language=javascript>";
- echo "alert('您还没有登陆!');";
- echo "top.location='".$basePath."release.php';";
- echo "</script>";
- return null;
- exit;
- }
- }
- else{
- echo "<script language=javascript>";
- echo "alert('您还没有登陆!');";
- echo "top.location='".$basePath."release.php';";
- echo "</script>";
- return null;
- exit;
- }
- }
- function bbwpsSetSession($path="",$data){
- global $sessionTime,$domain,$_COOKIE;
- if(!$data||!$path) return false;
- if(!is_dir($path)) return false;
- $sessionTime?null:$sessionTime=20;
- $dh=opendir($path);
- while ($file=readdir($dh)){
- if($file!="."&&$file!=".."){
- $dirArray[]=$file;
- }
- }
- closedir($dh);
- foreach ($dirArray as $file){
- if(strstr($file,"bbwpssess_")){
- $checktime=filectime($path.$file);
- if(($checktime+$sessionTime*60)<time()){
- unlink($path.$file);
- }
- }
- }
- if(isset($_COOKIE["PHPBBWPSSESSIONID"])&&$_COOKIE["PHPBBWPSSESSIONID"]){
- $sess_file_name=$_COOKIE["PHPBBWPSSESSIONID"];
- $_PHPBBWPSSESSION=getBBWPSSession($path);
- if(count($_PHPBBWPSSESSION)>0){
- foreach ($_PHPBBWPSSESSION as $key=>$value){
- $dataTmp[$key]=$value;
- }
- foreach ($data as $key=>$value){
- $dataTmp[$key]=$value;
- }
- }
- else{
- $dataTmp=$data;
- }
- }
- else{
- $sess_file_name=md5(microtime()*10+rand(1,10000));
- $dataTmp=$data;
- }
- $sess_string="<?PHPn";
- if(is_array($dataTmp)){
- foreach ($dataTmp as $key=>$value){
- $sess_string.='$_BBWPSSESSION['.$key.']="'.$value.'";'."n";
- }
- }
- else{
- $sess_string.='$_BBWPSSESSION['.$data.']="'.$data.'";'."n";
- }
- $sess_string.="?>";
- if(headers_sent()) echo "out";
- if(setcookie("PHPBBWPSSESSIONID",$sess_file_name,0,"/"))
- if(count($domain)>0){
- foreach ($domain as $dm){
- setcookie("PHPBBWPSLASTTIME",time(),0,"/",$dm);
- setcookie("PHPBBWPSADMINIP",getCurrentAdminIP(),0,"/",$dm);
- }
- }
- else{
- setcookie("PHPBBWPSLASTTIME",time(),0,"/");
- setcookie("PHPBBWPSADMINIP",getCurrentAdminIP(),0,"/");
- }
- if(is_writeable($path)){
- $fp=fopen($path."bbwpssess_".$sess_file_name.".php","w");
- fwrite($fp,$sess_string,strlen($sess_string));
- fclose($fp);
- return true;
- }
- else{
- return false;
- }
- }
- function getBBWPSSession($path="./"){
- global $sessionTime,$domain,$basePath,$_COOKIE;
- $sess_file_name=$path."bbwpssess_".$_COOKIE["PHPBBWPSSESSIONID"].".php";
- isset($_COOKIE["PHPBBWPSLASTTIME"])?$sess_time=$_COOKIE["PHPBBWPSLASTTIME"]:$sess_time=0;
- if(isset($_COOKIE["PHPBBWPSADMINIP"])){
- if(getCurrentAdminIP()!=$_COOKIE["PHPBBWPSADMINIP"]){
- return null;
- }
- }
- $sessionTime?null:$sessionTime=20;
- if(file_exists($sess_file_name)){
- if(($sess_time+$sessionTime*60)<time()){
- @unlink($sess_file_name);
- return null;
- }
- if(count($domain)>0){
- foreach ($domain as $dm){
- setcookie("PHPBBWPSLASTTIME",time(),0,"/",$dm);
- }
- }
- else{
- setcookie("PHPBBWPSLASTTIME",time(),0,"/");
- }
- include($sess_file_name);
- return $_BBWPSSESSION;
- }
- else{
- return null;
- }
- }
- function exitBBWPSSession($path="./"){
- global $basePath;
- $sess_file_name=$path."bbwpssess_".$_COOKIE["PHPBBWPSSESSIONID"].".php";
- @unlink($sess_file_name);
- setcookie("PHPBBWPSSESSIONID","",-1,"/");
- setcookie("PHPBBWPSLASTTIME","",-1,"/");
- $errorUrl = $basePath."release.php";
- exit("<script> parent.location.href='".$errorUrl."';</script>");
- }
- function getCurrentAdminIP(){
- if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
- $onlineip = getenv('HTTP_CLIENT_IP');
- } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
- $onlineip = getenv('HTTP_X_FORWARDED_FOR');
- } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
- $onlineip = getenv('REMOTE_ADDR');
- } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
- $onlineip = $_SERVER['REMOTE_ADDR'];
- }
- return $onlineip;
- }
- function MakeMd5($string,$num=1){
- for ($i=0;$i<$num;$i++){
- $string = md5($string);
- }
- return $string;
- }
- function DeMakeMd5($Ostring,$str){
- $stringNum=substr($Ostring,-1);
- if($Ostring==MakeMd5($str,$stringNum).$stringNum){
- return true;
- }
- else{
- return false;
- }
- }
- function EnMakeMd5($str){
- $num=rand(1,9);
- return MakeMd5($str,$num).$num;
- }
- function parseADTag($tmpObj,$tmpFile){
- global $basePath,$moduleID,$baseCheckCode;
- $basecheckcode=EnMakeMd5($baseCheckCode);
- $tmpString=file_get_contents($tmpFile);
- preg_match_all("/{ad_(.*?)}/is",$tmpString,$tagArray);
- if(is_array($tagArray)){
- foreach ($tagArray[0] as $key=>$value){
- $tmpObj->set_var("ad_".$tagArray[1][$key],"<script language="javascript" type="text/javascript" src="".$basePath."/api/parseAD.php?tag="."ad_".$tagArray[1][$key]."&basecheckcode=$basecheckcode&moduleID=$moduleID".""></script>");
- }
- }
- return $tmpObj;
- }
- function setBBWPSuserCredis($op="sum",$num,$forward,$reason,$sortuser){
- global $baseCheckCode,$_COOKIE,$basePath,$_GET,$articleid;
- $forward=rawurlencode($forward."&id=".EnMakeMd5($articleid));
- $reason=rawurldecode($reason);
- if(isset($_GET["basecheckcode"])&&isset($_GET["op"])){
- if(!DeMakeMd5($_GET["basecheckcode"],$baseCheckCode)||$_GET["op"]>0){
- switch ($_GET["op"]){
- case 1 :
- return false;
- break;
- case 2 :
- return false;
- break;
- }
- }
- else{
- if(!DeMakeMd5($_GET["id"],$articleid)){
- Meta(0,$basePath."/api/pay.php?basecheckcode=".EnMakeMd5($baseCheckCode)."&num=$num&op=$op&forward=$forward&check=".encode($sortuser,$baseCheckCode)."&reason=$reason&id=$articleid");
- }
- return true;
- }
- }
- else{
- Meta(0,$basePath."/api/pay.php?basecheckcode=".EnMakeMd5($baseCheckCode)."&num=$num&op=$op&forward=$forward&check=".encode($sortuser,$baseCheckCode)."&reason=$reason");
- }
- }
- function getBBWPSuserInfo($bbwpsusername){
- global $baseCheckCode,$basePath;
- $userInfoCacheUrl = $basePath."api/user.php?bbwpsusername=$bbwpsusername&basecheckcode=".EnMakeMd5($baseCheckCode);
- $x=new OutParse($userInfoCacheUrl);
- $userInfoArray=$x->GetItems();
- $userInfoArray=array_change_key_case($userInfoArray[1]);
- return $userInfoArray;
- }
- ?>