<?php
/*
[PPark!] (C)2007-2008 PPark Inc.
$Id: Discuz.class.php 2008-1-5 05:56:19
Author: Goodu [林晓庆]
Email: polo520@gmail.com
MSN: linxiaoqing@live.com
QQ: 36913636
Site: http://blog.oflv.cn
Copyright: PPark Inc.
*/
class Discuz{
var $keeptime; //应用程序保存该用户登录记录的时间,可为非负整数,单位秒
var $nowtime; //应用程序所在服务器当前时间(9 或 10 位数字 Unix Timestamp)
var $uid;
var $uname; //用户登录或注册的用户名,需要符合以下规则: 1:长度 1~15 个字符,不得为空 2:不得为 c:\con\con、游客(gb2312 或 big5 内码)、Guest 3:不得包含 (,)、(*)、(")、([TAB])、([SPACE])、([\r])、([\n])、(<)、(>)、(&)其中之一
var $upass; //用户密码经 MD5 不可逆加密后的值
var $email; //用户 Email 地址(50 个字节以内)
var $isadmin; //当前用户是否是应用程序的最高管理员,1=是,0=否。最高管理员的权限,将同步到论坛中去,其他下级管理员的身份将不进行同步,而由最高管理员分别在不同的系统中进行设置
var $credits; //当前用户在应用程序中的积分值,范围 -2147483648 到 2147483647,如果 Discuz! Passport 中设置了目标积分项,则用户登录时,Passport 会把应用程序传递过来的 credits 值同步到指定的论坛的指定积分项目中
var $gender; //当前用户的性别,1=男,2=女,0=未知
var $bday; //当前用户的生日,格式 yyyy-mm-dd
var $regip; //当前用户注册时的 IP 地址
var $regdate; //当前用户注册的时间(9 或 10 位数字 Unix Timestamp)
var $nickname; //当前用户的昵称(30 个字节以内,如传递此参数,必须打开相应用户组的昵称权限,否则用户在控制面板中提交个人资料时,会导致昵称失效)
var $site; //当前用户的主页地址(包含http://)
var $qq; //当前用户的 ICQ 账号
var $msn; //当前用户的 MSN Messenger 账号
var $yahoo; //当前用户的 Yahoo! Messanger 账号
var $forward; //当前用户的上一个来源页面
function Discuz(){
$this->setKeepTime(31536000);
$this->setNowTime(NowTime);
$this->setSite($GLOBALS['WEB_SITE']);
}
function setKeepTime($keeptime){
$this->keeptime = $keeptime;
}
function setNowTime($nowtime){
$this->nowtime = $nowtime;
}
function setUid($uid){
$this->uid = $uid;
}
function setUname($uname){
$this->uname = $uname;
}
function setPass($upass){
$this->upass = $upass;
}
function setEmail($email){
$this->email = $email;
}
function setIsAmdin($isadmin){
$this->isadmin = $isadmin;
}
function setCredits($credits){
$this->credits = $credits;
}
function setBday($bday){
$this->bday = $bday;
}
function setRegip($regip){
$this->regip = $regip;
}
function setRegdate($regdate){
$this->regdate = $regdate;
}
function setNickName($nickname){
$this->nickname = $nickname;
}
function setSite($site){
$this->site = $site;
}
function setQQ($qq){
$this->qq = $qq;
}
function setMSN($msn){
$this->msn = $msn;
}
function setYahoo($yahoo){
$this->yahoo = $yahoo;
}
function setForward($forward){
$this->forward = urldecode($forward);
}
/**
* 注册,注册前必须至少设置如下四个变量:
* $discuz->setUname();
* $discuz->setPass();
* $discuz->setEmail();
* $discuz->setForward();
*/
function Register(){
$member = array(
'cookietime' => $this->keeptime,
'time' => $this->nowtime,
'uid' => $this->uid,
'username' => $this->uname,
'password' => $this->upass,
'email' => $this->email,
);
$this->setPassport($member, "login");
}
/**
* 登录,登录前必须至少设置如下四个变量:
* $discuz->setUname();
* $discuz->setPass();
* $discuz->setEmail();
* $discuz->setForward();
*/
function Login($backtype=""){
$member = array(
'cookietime' => $this->keeptime,
'time' => $this->nowtime,
'uid' => $this->uid,
'username' => $this->uname,
'password' => $this->upass,
'email' => $this->email,
);
if ($backtype == "echo") {
return $this->setPassport($member, "login", "echo");
}else{
$this->setPassport($member, "login");
}
}
/**
* 退出,退出前必须至少设置如下三个变量:
* $discuz->setUname();
* $discuz->setPass();
* $discuz->setForward();
*/
function Logout(){
$member = array(
'cookietime' => $this->keeptime,
'time' => $this->nowtime,
'uid' => $this->uid,
'username' => $this->uname,
'password' => $this->upass
);
$this->setPassport($member, "logout");
}
function Update(){
$member = array(
'cookietime' => $this->keeptime,
'time' => $this->nowtime,
'uid' => $this->uid,
'username' => $this->uname,
'password' => $this->upass,
'email' => $this->email,
'nickname' => $this->nickname,
'site' => $this->site,
'qq' => $this->qq,
'msn' => $this->msn,
);
$this->setPassport($member, "login");
}
function setPassport($member, $action, $type=""){
$auth = $this->passport_encrypt($this->passport_encode($member), DISCUZ_PASSPORT);
$location = $GLOBALS['BBSDATA']['path']."/api/passport.php"
. "?action=".$action
. "&auth=".rawurlencode($auth)
. "&verify=".md5($action . $auth . $this->forward . DISCUZ_PASSPORT)
. "&forward=".rawurlencode($this->forward);
if($type == "echo"){
return $location;
}else{
header("Location: " . $location);
}
}
function passport_encrypt($txt, $key) {
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($this->passport_key($tmp, $key));
}
function passport_decrypt($txt, $key) {
$txt = $this->passport_key(base64_decode($txt), $key);
$tmp = '';
for ($i = 0; $i < strlen($txt); $i++) {
$tmp .= $txt[$i] ^ $txt[++$i];
}
return $tmp;
}
function passport_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 passport_encode($array) {
$arrayenc = array();
foreach($array as $key => $val) {
$arrayenc[] = $key.'='.urlencode($val);
}
return implode('&', $arrayenc);
}
};
?>
使用方法: 复制PHP内容到剪贴板 PHP代码:$discuz = new Discuz();
$discuz->setUname($user['uname']);
$discuz->setPass($user['upass']);
$discuz->setEmail($user['email']);
$discuz->setForward($fromURL);
$discuz->Login();
此类为原创类,转载请保留版权信息,谢谢!
/*
[PPark!] (C)2007-2008 PPark Inc.
$Id: Discuz.class.php 2008-1-5 05:56:19
Author: Goodu [林晓庆]
Email: polo520@gmail.com
MSN: linxiaoqing@live.com
QQ: 36913636
Site: http://blog.oflv.cn
Copyright: PPark Inc.
*/
class Discuz{
var $keeptime; //应用程序保存该用户登录记录的时间,可为非负整数,单位秒
var $nowtime; //应用程序所在服务器当前时间(9 或 10 位数字 Unix Timestamp)
var $uid;
var $uname; //用户登录或注册的用户名,需要符合以下规则: 1:长度 1~15 个字符,不得为空 2:不得为 c:\con\con、游客(gb2312 或 big5 内码)、Guest 3:不得包含 (,)、(*)、(")、([TAB])、([SPACE])、([\r])、([\n])、(<)、(>)、(&)其中之一
var $upass; //用户密码经 MD5 不可逆加密后的值
var $email; //用户 Email 地址(50 个字节以内)
var $isadmin; //当前用户是否是应用程序的最高管理员,1=是,0=否。最高管理员的权限,将同步到论坛中去,其他下级管理员的身份将不进行同步,而由最高管理员分别在不同的系统中进行设置
var $credits; //当前用户在应用程序中的积分值,范围 -2147483648 到 2147483647,如果 Discuz! Passport 中设置了目标积分项,则用户登录时,Passport 会把应用程序传递过来的 credits 值同步到指定的论坛的指定积分项目中
var $gender; //当前用户的性别,1=男,2=女,0=未知
var $bday; //当前用户的生日,格式 yyyy-mm-dd
var $regip; //当前用户注册时的 IP 地址
var $regdate; //当前用户注册的时间(9 或 10 位数字 Unix Timestamp)
var $nickname; //当前用户的昵称(30 个字节以内,如传递此参数,必须打开相应用户组的昵称权限,否则用户在控制面板中提交个人资料时,会导致昵称失效)
var $site; //当前用户的主页地址(包含http://)
var $qq; //当前用户的 ICQ 账号
var $msn; //当前用户的 MSN Messenger 账号
var $yahoo; //当前用户的 Yahoo! Messanger 账号
var $forward; //当前用户的上一个来源页面
function Discuz(){
$this->setKeepTime(31536000);
$this->setNowTime(NowTime);
$this->setSite($GLOBALS['WEB_SITE']);
}
function setKeepTime($keeptime){
$this->keeptime = $keeptime;
}
function setNowTime($nowtime){
$this->nowtime = $nowtime;
}
function setUid($uid){
$this->uid = $uid;
}
function setUname($uname){
$this->uname = $uname;
}
function setPass($upass){
$this->upass = $upass;
}
function setEmail($email){
$this->email = $email;
}
function setIsAmdin($isadmin){
$this->isadmin = $isadmin;
}
function setCredits($credits){
$this->credits = $credits;
}
function setBday($bday){
$this->bday = $bday;
}
function setRegip($regip){
$this->regip = $regip;
}
function setRegdate($regdate){
$this->regdate = $regdate;
}
function setNickName($nickname){
$this->nickname = $nickname;
}
function setSite($site){
$this->site = $site;
}
function setQQ($qq){
$this->qq = $qq;
}
function setMSN($msn){
$this->msn = $msn;
}
function setYahoo($yahoo){
$this->yahoo = $yahoo;
}
function setForward($forward){
$this->forward = urldecode($forward);
}
/**
* 注册,注册前必须至少设置如下四个变量:
* $discuz->setUname();
* $discuz->setPass();
* $discuz->setEmail();
* $discuz->setForward();
*/
function Register(){
$member = array(
'cookietime' => $this->keeptime,
'time' => $this->nowtime,
'uid' => $this->uid,
'username' => $this->uname,
'password' => $this->upass,
'email' => $this->email,
);
$this->setPassport($member, "login");
}
/**
* 登录,登录前必须至少设置如下四个变量:
* $discuz->setUname();
* $discuz->setPass();
* $discuz->setEmail();
* $discuz->setForward();
*/
function Login($backtype=""){
$member = array(
'cookietime' => $this->keeptime,
'time' => $this->nowtime,
'uid' => $this->uid,
'username' => $this->uname,
'password' => $this->upass,
'email' => $this->email,
);
if ($backtype == "echo") {
return $this->setPassport($member, "login", "echo");
}else{
$this->setPassport($member, "login");
}
}
/**
* 退出,退出前必须至少设置如下三个变量:
* $discuz->setUname();
* $discuz->setPass();
* $discuz->setForward();
*/
function Logout(){
$member = array(
'cookietime' => $this->keeptime,
'time' => $this->nowtime,
'uid' => $this->uid,
'username' => $this->uname,
'password' => $this->upass
);
$this->setPassport($member, "logout");
}
function Update(){
$member = array(
'cookietime' => $this->keeptime,
'time' => $this->nowtime,
'uid' => $this->uid,
'username' => $this->uname,
'password' => $this->upass,
'email' => $this->email,
'nickname' => $this->nickname,
'site' => $this->site,
'qq' => $this->qq,
'msn' => $this->msn,
);
$this->setPassport($member, "login");
}
function setPassport($member, $action, $type=""){
$auth = $this->passport_encrypt($this->passport_encode($member), DISCUZ_PASSPORT);
$location = $GLOBALS['BBSDATA']['path']."/api/passport.php"
. "?action=".$action
. "&auth=".rawurlencode($auth)
. "&verify=".md5($action . $auth . $this->forward . DISCUZ_PASSPORT)
. "&forward=".rawurlencode($this->forward);
if($type == "echo"){
return $location;
}else{
header("Location: " . $location);
}
}
function passport_encrypt($txt, $key) {
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($this->passport_key($tmp, $key));
}
function passport_decrypt($txt, $key) {
$txt = $this->passport_key(base64_decode($txt), $key);
$tmp = '';
for ($i = 0; $i < strlen($txt); $i++) {
$tmp .= $txt[$i] ^ $txt[++$i];
}
return $tmp;
}
function passport_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 passport_encode($array) {
$arrayenc = array();
foreach($array as $key => $val) {
$arrayenc[] = $key.'='.urlencode($val);
}
return implode('&', $arrayenc);
}
};
?>
使用方法: 复制PHP内容到剪贴板 PHP代码:$discuz = new Discuz();
$discuz->setUname($user['uname']);
$discuz->setPass($user['upass']);
$discuz->setEmail($user['email']);
$discuz->setForward($fromURL);
$discuz->Login();
此类为原创类,转载请保留版权信息,谢谢!