<?php
if(!defined('IN_PDAFANS')){
exit('Access Denied');
}
class cls_discuz {
var $cookiepre = 'cdb_'; // cookie 前缀
var $cookiedomain = '.pdafans.com'; // cookie 作用域
var $cookiepath = '/'; // cookie 作用路径
var $tablepre = 'cdb_'; // 整合discuz论坛 数据库表名默认前缀为'cdb_';
var $onlinehold = 1800; // 在线保持时间
var $auth_key='';
var $sid;
var $auth_values;
var $sessionexists=0;
function __construct($cookiepre,$cookiedomain,$cookiepath,$tablepre,$onlinehold) {
$this->cls_discuz($cookiepre,$cookiedomain,$cookiepath,$tablepre,$onlinehold);
}
function cls_discuz($cookiepre,$cookiedomain,$cookiepath,$tablepre,$onlinehold) {
$this->cookiepre=$cookiepre;
$this->cookiedomain=$cookiemain;
$this->tablepre=$tablepre;
$this->onlinehold=$onlinehold
$this->set_auth_key();
}
function set_auth_key() {
$result=mysql_query("SELECT value FROM cdb_settings WHERE variable='authkey'");
$row=mysql_fetch_array($result);
$authkey=$row['value'];
mysql_free_result($result);
$this->$auth_key = md5($authkey.$_SERVER['HTTP_USER_AGENT']);
}
function set_sid() {
$this->sid = pdafans_daddslashes( isset($_COOKIE[$this->cookiepre.'sid']) ? $_COOKIE[$this->cookiepre.'sid'] : '');
if($this->sid) {
$this->sessionexists=1;
}
else {
$this->sessionexists=0;
$this->sid = $this->rand_code(6);
}
if(empty($_COOKIE[$this->cookiepre.'sid']) || $this->sid != $_COOKIE[$this->cookiepre.'sid']) {
set_cookie('sid', $this->sid, 604800);
}
}
function get_sid() {
if($this->sid) {
return $this->sid;
}
else {
$this->set_sid();
return $this->sid;
}
}
function discuz_login($password,$secques,$uid,$type='ENCODE') {
$this->auth_values=$this->discuz6_code("$password\t$secques\t$uid", $type);
set_cookie('auth', $this->auth_values, 604800);
}
function discuz_logout() {
clear_cookies();
}
function update_session()
{
global $timestamp,$onlineip,$pdafans_dev_uid, $pdafans_dev_username, $seccode,$groupid;
if($this->sid)
{
$query=mysql_query("SELECT sid FROM {$this->tablepre}sessions WHERE sid='$this->sid'");
if(mysql_num_rows($query)){
$row=mysql_fetch_array($query);
$this->sid=$row['sid'];
$sessexist=empty($this->sid) ? 0 : 1 ;
}
if($sessexist == 1)
{
mysql_query("UPDATE {$tablepre}sessions SET uid='$pdafans_dev_uid', username='$pdafans_dev_username', groupid='$groupid',lastactivity='$timestamp', lastolupdate='$timestamp', seccode='$seccode' WHERE sid='$this->sid'") or die('update error!');
}
else
{
$ips = explode('.', $onlineip);
mysql_query("DELETE FROM {$tablepre}sessions WHERE sid='$this->sid' OR lastactivity<($timestamp-$this->onlinehold) OR ('$pdafans_dev_uid'<>'0' AND uid='$pdafans_dev_uid') OR (uid='0' AND ip1='$ips[0]' AND ip2='$ips[1]' AND ip3='$ips[2]' AND ip4='$ips[3]' AND lastactivity>$timestamp-60)");
mysql_query("INSERT INTO {$tablepre}sessions (sid, ip1, ip2, ip3, ip4, uid, username, groupid, lastactivity, lastolupdate, seccode)
VALUES ('$this->sid', '$ips[0]', '$ips[1]', '$ips[2]', '$ips[3]', '$pdafans_dev_uid', '$pdafans_dev_username', '$groupid', '$timestamp', '$timestamp', '$seccode')");
}
}
}
function rand_code($length, $numeric = 0) {
PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
if($numeric) {
$hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
} else {
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
}
return $hash;
}
//加密安全问题函数
function pdafans_quescrypt($questionid, $answer) {
return $questionid > 0 && $answer != '' ? substr(md5($answer.md5($questionid)), 16, 8) : '';
}
function discuz6_code($string, $operation, $key = ''){
$key = md5($key ? $key : $this->auth_key);
$key_length = strlen($key);
$string = $operation == 'DECODE' ? base64_decode($string) : substr(md5($string.$key), 0, 8).$string;
$string_length = strlen($string);
$rndkey = $box = array();
$result = '';
for($i = 0; $i <= 255; $i++) {
$rndkey[$i] = ord($key[$i % $key_length]);
$box[$i] = $i;
}
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, 8) == substr(md5(substr($result, 8).$key), 0, 8)) {
return substr($result, 8);
} else {
return '';
}
} else {
return str_replace('=', '', base64_encode($result));
}
}
}
?>
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【项目资源】:包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。【项目质量】:所有源码都经过严格测试,可以直接运行。功能在确认正常工作后才上传。【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。【附加价值】:项目具有较高的学习借鉴价值,也可直接拿来修改复刻。对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。【沟通交流】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。鼓励下载和使用,并欢迎大家互相学习,共同进步。
资源推荐
资源详情
资源评论
收起资源包目录
[其他类别]整合discuz6.0的php的class_cls_discuz.rar (1个子文件)
[其他类别]整合discuz6.0的php的class_cls_discuz
cls_discuz.php 5KB
共 1 条
- 1
资源评论
心梓知识
- 粉丝: 6158
- 资源: 3万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- MMDF1N05ER2G-VB一款SOP8封装2个N-Channel场效应MOS管
- zipkin-server-3.3.0-exec.jar
- MI9933-VB一款SOP8封装2个P-Channel场效应MOS管
- zipkin-server-2.24.4-exec.jar
- MI4953-VB一款SOP8封装2个P-Channel场效应MOS管
- 基于Akka模拟实现Spark Standalone.pdf
- MI4946-VB一款SOP8封装2个N-Channel场效应MOS管
- 毕业答辩模板(动态模板)苹果IOS星空通用论文答辩模板
- 有效cookie值获取方式汇总
- 基于python实现的英雄联盟知识图谱问答系统源码(期末大作业).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功