Rumah  >  Artikel  >  pembangunan bahagian belakang  >  onethink跟phpwind共用

onethink跟phpwind共用

WBOY
WBOYasal
2016-06-13 12:16:09927semak imbas

onethink和phpwind共用

将onethink和phpwind数据库安装在一起,使用通用的表前缀。

将onethink的member表指向phpwind有user表

以下为onethink安装在根目录下,phpwind安装在bbs目录下的情况

修改onethink中的is_login函数

function is_login(){	$site=include('./bbs/data/cache/config.php');	C('BBS_SITE_SET',$site['data']['site']);			if (!($userCookie = \Org\util\Pw::getCookie('winduser'))) {			return 0;	} else {			list($uid, $password) = explode("\t", \Org\util\Pw::decrypt($userCookie));			$user_session = session('user_auth');			if (empty($user_session)||$user_session['uid']!=$uid) {				//$user = new User\Api\UserApi();				//$info = $user->info($uid);				/* 记录登录SESSION和COOKIES */				$auth = array(					'uid'             => $uid,					'username'        => get_username($uid),					'last_login_time' => NOW_TIME,				);				session('user_auth', $auth);				session('user_auth_sign', data_auth_sign($auth));			}			return $uid;	}/*        $user = session('user_auth');        if (empty($user)) {            return 0;        } else {            return session('user_auth_sign') == data_auth_sign($user) ? $user['uid'] : 0;        }*/}
think库中添加Org/util/pw.class.php和Org/WindCookie.class.php

1.WindCookie.class.php

<?phpnamespace Org;/** * cookie操作类 *  * 使用的时候全部采用静态的方式使用该类中的所有方法: * <code> * Wind::import('WIND:http.cookie.WindCookie'); * WindCookie::set('name', 'test'); *  *  * @author Qian Su  * @copyright ©2003-2103 phpwind.com * @license http://www.windframework.com * @version $Id: WindCookie.php 3760 2012-10-11 08:02:25Z yishuo $ * @package http * @subpackage cookie */class WindCookie {	/**	 * 设置cookie	 * 	 * @param string $name cookie名称	 * @param string $value cookie值,默认为null	 * @param boolean $encode 是否使用 MIME base64 对数据进行编码,默认是false即不进行编码	 * @param string|int $expires 过期时间,默认为null即会话cookie,随着会话结束将会销毁	 * @param string $path cookie保存的路径,默认为null即采用默认	 * @param string $domain cookie所属域,默认为null即不设置	 * @param boolean $secure 是否安全连接,默认为false即不采用安全链接	 * @param boolean $httponly 是否可通过客户端脚本访问,默认为false即客户端脚本可以访问cookie	 * @return boolean 设置成功返回true,失败返回false	 */	public static function set($name, $value = null, $encode = false, $expires = null, $path = null, $domain = null, $secure = false, $httponly = false) {		if (empty($name)) return false;		$encode && $value && $value = base64_encode($value);		$path = $path ? $path : '/';		setcookie($name, $value, $expires, $path, $domain, $secure, $httponly);		return true;	}	/**	 * 根据cookie的名字删除cookie	 * 	 * @param string $name cookie名称	 * @return boolean 删除成功返回true	 */	public static function delete($name) {		if (self::exist($name)) {			self::set($name, '');			unset($_COOKIE[$name]);		}		return true;	}	/**	 * 取得指定名称的cookie值	 * 	 * @param string $name cookie名称	 * @param boolean $dencode 是否对cookie值进行过解码,默认为false即不用解码	 * @return mixed 获取成功将返回保存的cookie值,获取失败将返回false	 */	public static function get($name, $dencode = false) {		if (self::exist($name)) {			$value = $_COOKIE[$name];			$value && $dencode && $value = base64_decode($value);			return $value ? $value : $value;		}		return false;	}	/**	 * 移除全部cookie	 * 	 * @return boolean 移除成功将返回true	 */	public static function deleteAll() {		$_COOKIE = array();		return true;	}	/**	 * 判断cookie是否存在	 * 	 * @param string $name cookie名称	 * @return boolean 如果不存在则返回false,否则返回true	 */	public static function exist($name) {		return isset($_COOKIE[$name]);	}}

2.pw.class.php

<?phpnamespace Org\util;use Org\WindCookie;/** * 工具类库 * * @author Jianmin Chen <[email&#160;protected]> * @copyright ©2003-2103 phpwind.com * @license http://www.phpwind.com * @version $Id: Pw.php 28776 2013-05-23 08:46:10Z jieyin $ * @package library */class Pw {	/**	 * 取得指定名称的cookie值	 *	 * @param string $name cookie名称	 * @param string $pre cookie前缀,默认为null即没有前缀	 * @return boolean	 */	public static function getCookie($name) {		$site = C('BBS_SITE_SET');		$pre = $site['cookie.pre'];		$pre && $name = $pre . '_' . $name;		return WindCookie::get($name);	}	/**	 * 设置cookie	 *	 * @param string $name cookie名称	 * @param string $value cookie值,默认为null	 * @param string|int $expires 过期时间,默认为null即会话cookie,随着会话结束将会销毁	 * @param string $pre cookie前缀,默认为null即没有前缀	 * @param boolean $httponly	 * @return boolean	 */	public static function setCookie($name, $value = null, $expires = null, $httponly = false) {		$path = $domain = null;		$site = C('BBS_SITE_SET');		$pre = $site['cookie.pre'];		$pre && $name = $pre . '_' . $name;		$expires && $expires += time();		return WindCookie::set($name, $value, false, $expires, $path, $domain, false, $httponly);	}	/**	 * 加密方法	 *	 * @param string $str	 * @param string $key	 * @return string	 */	public static function encrypt($str, $key = '') {		$site = C('BBS_SITE_SET');		$key || $key = $site['hash'];		return base64_encode(self::iencrypt($str, $key));	}		/**	 * 解密方法	 *	 * @param string $str	 * @param string $key	 * @return string	 */	public static function decrypt($str, $key = '') {		$site = C('BBS_SITE_SET');		$key || $key = $site['hash'];		return self::idecrypt(base64_decode($str), $key);	}	/**	 * 密码加密存储	 *	 * @param string $pwd	 * @return string	 */	public static function getPwdCode($pwd) {		$site = C('BBS_SITE_SET');		return md5($pwd . $site['hash']);	}	public function iencrypt($str, $key) {		if ($str == '') return '';		if (!$key || !is_string($key)) {			return '';		}		$v = self::str2long($str, true);		$k = self::str2long($key, false);		if (count($k) > 2 & 3;			for ($p = 0; $p > 5 & 0x07ffffff) ^ $y > 3 & 0x1fffffff) ^ $z > 5 & 0x07ffffff) ^ $y > 3 & 0x1fffffff) ^ $z > 2 & 3;			for ($p = $n; $p > 0; $p--) {				$z = $v[$p - 1];				$mx = self::int32((($z >> 5 & 0x07ffffff) ^ $y > 3 & 0x1fffffff) ^ $z > 5 & 0x07ffffff) ^ $y > 3 & 0x1fffffff) ^ $z 	 */	private function str2long($s, $w) {		$v = unpack("V*", $s . str_repeat("\0", (4 - strlen($s) % 4) & 3));		$v = array_values($v);		if ($w) $v[count($v)] = strlen($s);		return $v;	}	/**	 * @param int $n	 * @return number	 */	private function int32($n) {		while ($n >= 2147483648)			$n -= 4294967296;		while ($n <br>onethink中的user模块作相应修改<br><div class="clear">
                 
              
              
        
            </div>
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya:请问一个关于php数组有关问题Artikel seterusnya:PHP 正则(二)