checkModuleSession.php
上传用户:yttaitong
上传日期:2009-05-10
资源大小:128k
文件大小:8k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

PHP

  1. <?php
  2. /*
  3.     [BBWPS!] (C)2006-2010 小蜜蜂版权所有.
  4. This is NOT a freeware, use is subject to license terms
  5.     时间:2007年12月
  6.     描述:检查用户是否登录
  7. */
  8. function checkCookie(){
  9. global $baseCheckCode,$_COOKIE,$basePath,$_GET;
  10. if(!$_COOKIE['bbwps_user']||!$_COOKIE['bbwps_pwd']||!$_COOKIE['bbwps_ip']||!$_COOKIE['bbwps_check']){
  11. if(!$_GET['bbwps_user']||!$_GET['bbwps_pwd']||!$_GET['bbwps_ip']||!$_GET['bbwps_check']){
  12. ExeSuccess("您还没有登陆",$basePath);
  13. }
  14. else {
  15. extract($_GET);
  16. }
  17. }
  18. else {
  19. extract($_COOKIE);
  20. }
  21. $checkPass = decoded($bbwps_check,$baseCheckCode);
  22. $loginArray = array("bbwps_user"=>$bbwps_user,"bbwps_regctrl"=>$bbwps_regctrl,"bbwps_permit"=>$bbwps_permit);
  23. if($checkPass==$bbwps_pwd)
  24. return($loginArray);
  25. else ExeSuccess("您还没有登陆",$basePath);
  26. }
  27. function encode_key($txt, $encrypt_key) {
  28. $encrypt_key = md5($encrypt_key);
  29. $ctr = 0;
  30. $tmp = '';
  31. for($i = 0; $i < strlen($txt); $i++) {
  32. $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
  33. $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
  34. }
  35. return $tmp;
  36. }
  37. function decoded($codeString,$key){
  38. $txt = $codeString;
  39. $txt = encode_key(base64_decode($txt), $key);
  40. $tmp = '';
  41. for($i = 0;$i < strlen($txt); $i++) {
  42. $md5 = $txt[$i];
  43. $tmp .= $txt[++$i] ^ $md5;
  44. }
  45. return $tmp;
  46. }
  47. function encode($codeString,$key){
  48. $txt = $codeString;
  49. srand((double)microtime() * 1000000);
  50. $encrypt_key = md5(rand(0, 32000));
  51. $ctr = 0;
  52. $tmp = '';
  53. for($i = 0;$i < strlen($txt); $i++) {
  54. $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
  55. $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
  56. }
  57. return base64_encode(encode_key($tmp, $key));
  58. }
  59. function isLogin($path){
  60. global $installPath,$host,$basePath;
  61. if(!$path) return null;
  62. $popedom="http://".$host.$installPath."/";
  63. $_bbwspSession=getBBWPSSession($path);
  64. if(count($_bbwspSession)>0){
  65. $checkpopedomNum=substr($_bbwspSession["BBWPS_MODULE_POPEDOM"],-1);
  66. $checkpopedom=MakeMd5($popedom,$checkpopedomNum).$checkpopedomNum;
  67. if($checkpopedom==$_bbwspSession["BBWPS_MODULE_POPEDOM"]){
  68. return $_bbwspSession["BBWPS_MODULE_USERNAME"];
  69. }
  70. else{
  71. echo "<script language=javascript>";
  72. echo "alert('您还没有登陆!');";
  73. echo "top.location='".$basePath."release.php';";
  74. echo "</script>";
  75. return null;
  76. exit;
  77. }
  78. }
  79. else{
  80. echo "<script language=javascript>";
  81. echo "alert('您还没有登陆!');";
  82. echo "top.location='".$basePath."release.php';";
  83. echo "</script>";
  84. return null;
  85. exit;
  86. }
  87. }
  88. function bbwpsSetSession($path="",$data){
  89. global $sessionTime,$domain,$_COOKIE;
  90. if(!$data||!$path) return false;
  91. if(!is_dir($path)) return false;
  92. $sessionTime?null:$sessionTime=20;
  93. $dh=opendir($path);
  94. while ($file=readdir($dh)){
  95. if($file!="."&&$file!=".."){
  96. $dirArray[]=$file;
  97. }
  98. }
  99. closedir($dh);
  100. foreach ($dirArray as $file){
  101. if(strstr($file,"bbwpssess_")){
  102. $checktime=filectime($path.$file);
  103. if(($checktime+$sessionTime*60)<time()){
  104. unlink($path.$file);
  105. }
  106. }
  107. }
  108. if(isset($_COOKIE["PHPBBWPSSESSIONID"])&&$_COOKIE["PHPBBWPSSESSIONID"]){
  109. $sess_file_name=$_COOKIE["PHPBBWPSSESSIONID"];
  110. $_PHPBBWPSSESSION=getBBWPSSession($path);
  111. if(count($_PHPBBWPSSESSION)>0){
  112. foreach ($_PHPBBWPSSESSION as $key=>$value){
  113. $dataTmp[$key]=$value;
  114. }
  115. foreach ($data as $key=>$value){
  116. $dataTmp[$key]=$value;
  117. }
  118. }
  119. else{
  120. $dataTmp=$data;
  121. }
  122. }
  123. else{
  124. $sess_file_name=md5(microtime()*10+rand(1,10000));
  125. $dataTmp=$data;
  126. }
  127. $sess_string="<?PHPn";
  128. if(is_array($dataTmp)){
  129. foreach ($dataTmp as $key=>$value){
  130. $sess_string.='$_BBWPSSESSION['.$key.']="'.$value.'";'."n";
  131. }
  132. }
  133. else{
  134. $sess_string.='$_BBWPSSESSION['.$data.']="'.$data.'";'."n";
  135. }
  136. $sess_string.="?>";
  137. if(headers_sent()) echo "out";
  138. if(setcookie("PHPBBWPSSESSIONID",$sess_file_name,0,"/"))
  139. if(count($domain)>0){
  140. foreach ($domain as $dm){
  141. setcookie("PHPBBWPSLASTTIME",time(),0,"/",$dm);
  142. setcookie("PHPBBWPSADMINIP",getCurrentAdminIP(),0,"/",$dm);
  143. }
  144. }
  145. else{
  146. setcookie("PHPBBWPSLASTTIME",time(),0,"/");
  147. setcookie("PHPBBWPSADMINIP",getCurrentAdminIP(),0,"/");
  148. }
  149. if(is_writeable($path)){
  150. $fp=fopen($path."bbwpssess_".$sess_file_name.".php","w");
  151. fwrite($fp,$sess_string,strlen($sess_string));
  152. fclose($fp);
  153. return true;
  154. }
  155. else{
  156. return false;
  157. }
  158. }
  159. function getBBWPSSession($path="./"){
  160. global $sessionTime,$domain,$basePath,$_COOKIE;
  161. $sess_file_name=$path."bbwpssess_".$_COOKIE["PHPBBWPSSESSIONID"].".php";
  162. isset($_COOKIE["PHPBBWPSLASTTIME"])?$sess_time=$_COOKIE["PHPBBWPSLASTTIME"]:$sess_time=0;
  163. if(isset($_COOKIE["PHPBBWPSADMINIP"])){
  164. if(getCurrentAdminIP()!=$_COOKIE["PHPBBWPSADMINIP"]){
  165. return null;
  166. }
  167. }
  168. $sessionTime?null:$sessionTime=20;
  169. if(file_exists($sess_file_name)){
  170. if(($sess_time+$sessionTime*60)<time()){
  171. @unlink($sess_file_name);
  172. return null;
  173. }
  174. if(count($domain)>0){
  175. foreach ($domain as $dm){
  176. setcookie("PHPBBWPSLASTTIME",time(),0,"/",$dm);
  177. }
  178. }
  179. else{
  180. setcookie("PHPBBWPSLASTTIME",time(),0,"/");
  181. }
  182. include($sess_file_name);
  183. return $_BBWPSSESSION;
  184. }
  185. else{
  186. return null;
  187. }
  188. }
  189. function exitBBWPSSession($path="./"){
  190. global $basePath;
  191. $sess_file_name=$path."bbwpssess_".$_COOKIE["PHPBBWPSSESSIONID"].".php";
  192. @unlink($sess_file_name);
  193. setcookie("PHPBBWPSSESSIONID","",-1,"/");
  194. setcookie("PHPBBWPSLASTTIME","",-1,"/");
  195. $errorUrl = $basePath."release.php";
  196. exit("<script> parent.location.href='".$errorUrl."';</script>");
  197. }
  198. function getCurrentAdminIP(){
  199. if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
  200. $onlineip = getenv('HTTP_CLIENT_IP');
  201. } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
  202. $onlineip = getenv('HTTP_X_FORWARDED_FOR');
  203. } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
  204. $onlineip = getenv('REMOTE_ADDR');
  205. } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
  206. $onlineip = $_SERVER['REMOTE_ADDR'];
  207. }
  208. return $onlineip;
  209. }
  210. function MakeMd5($string,$num=1){
  211. for ($i=0;$i<$num;$i++){
  212. $string = md5($string);
  213. }
  214. return $string;
  215. }
  216. function DeMakeMd5($Ostring,$str){
  217. $stringNum=substr($Ostring,-1);
  218. if($Ostring==MakeMd5($str,$stringNum).$stringNum){
  219. return true;
  220. }
  221. else{
  222. return false;
  223. }
  224. }
  225. function EnMakeMd5($str){
  226. $num=rand(1,9);
  227. return MakeMd5($str,$num).$num;
  228. }
  229. function parseADTag($tmpObj,$tmpFile){
  230. global $basePath,$moduleID,$baseCheckCode;
  231. $basecheckcode=EnMakeMd5($baseCheckCode);
  232. $tmpString=file_get_contents($tmpFile);
  233. preg_match_all("/{ad_(.*?)}/is",$tmpString,$tagArray);
  234. if(is_array($tagArray)){
  235. foreach ($tagArray[0] as $key=>$value){
  236. $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>");
  237. }
  238. }
  239. return $tmpObj;
  240. }
  241. function setBBWPSuserCredis($op="sum",$num,$forward,$reason,$sortuser){
  242. global $baseCheckCode,$_COOKIE,$basePath,$_GET,$articleid;
  243. $forward=rawurlencode($forward."&id=".EnMakeMd5($articleid));
  244. $reason=rawurldecode($reason);
  245. if(isset($_GET["basecheckcode"])&&isset($_GET["op"])){
  246. if(!DeMakeMd5($_GET["basecheckcode"],$baseCheckCode)||$_GET["op"]>0){
  247. switch ($_GET["op"]){
  248. case 1 :
  249. return false;
  250. break;
  251. case 2 :
  252. return false;
  253. break;
  254. }
  255. }
  256. else{
  257. if(!DeMakeMd5($_GET["id"],$articleid)){
  258. Meta(0,$basePath."/api/pay.php?basecheckcode=".EnMakeMd5($baseCheckCode)."&num=$num&op=$op&forward=$forward&check=".encode($sortuser,$baseCheckCode)."&reason=$reason&id=$articleid");
  259. }
  260. return true;
  261. }
  262. }
  263. else{
  264. Meta(0,$basePath."/api/pay.php?basecheckcode=".EnMakeMd5($baseCheckCode)."&num=$num&op=$op&forward=$forward&check=".encode($sortuser,$baseCheckCode)."&reason=$reason");
  265. }
  266. }
  267. function getBBWPSuserInfo($bbwpsusername){
  268. global $baseCheckCode,$basePath;
  269. $userInfoCacheUrl = $basePath."api/user.php?bbwpsusername=$bbwpsusername&basecheckcode=".EnMakeMd5($baseCheckCode);
  270. $x=new OutParse($userInfoCacheUrl);
  271. $userInfoArray=$x->GetItems();
  272. $userInfoArray=array_change_key_case($userInfoArray[1]);
  273. return $userInfoArray;
  274. ?>