• 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 = OrgutilPw::getCookie('winduser'))) {
    			return 0;
    	} else {
    			list($uid, $password) = explode("	", OrgutilPw::decrypt($userCookie));
    			$user_session = session('user_auth');
    			if (empty($user_session)||$user_session['uid']!=$uid) {
    				//$user = new UserApiUserApi();
    				//$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

    <?php
    namespace Org;
    
    /**
     * cookie操作类
     * 
     * 使用的时候所有採用静态的方式使用该类中的所有方法:
     * <code>
     * Wind::import('WIND:http.cookie.WindCookie');
     * WindCookie::set('name', 'test');
     * </code>
     * 
     * @author Qian Su <aoxue.1988.su.qian@163.com>
     * @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 是否可通过client脚本訪问,默觉得false即client脚本能够訪问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

    <?php
    namespace Orgutil;
    use OrgWindCookie;
    /**
     * 工具类库
     *
     * @author Jianmin Chen <sky_hold@163.com>
     * @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);
    	}
    
    	/**
    	 * password加密存储
    	 *
    	 * @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) < 4) {
    			for ($i = count($k); $i < 4; $i++) {
    				$k[$i] = 0;
    			}
    		}
    		$n = count($v) - 1;
    		
    		$z = $v[$n];
    		$y = $v[0];
    		$delta = 0x9E3779B9;
    		$q = floor(6 + 52 / ($n + 1));
    		$sum = 0;
    		while (0 < $q--) {
    			$sum = self::int32($sum + $delta);
    			$e = $sum >> 2 & 3;
    			for ($p = 0; $p < $n; $p++) {
    				$y = $v[$p + 1];
    				$mx = self::int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ self::int32(
    					($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
    				$z = $v[$p] = self::int32($v[$p] + $mx);
    			}
    			$y = $v[0];
    			$mx = self::int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ self::int32(
    				($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
    			$z = $v[$n] = self::int32($v[$n] + $mx);
    		}
    		return self::long2str($v, false);
    	}
    
    	/* (non-PHPdoc)
    	 * @see IWindSecurity::decrypt()
    	 */
    	public function idecrypt($str, $key) {
    		if ($str == '') return '';
    		if (!$key || !is_string($key)) {
    			return '';
    		}
    		$v = self::str2long($str, false);
    		$k = self::str2long($key, false);
    		if (count($k) < 4) {
    			for ($i = count($k); $i < 4; $i++) {
    				$k[$i] = 0;
    			}
    		}
    		$n = count($v) - 1;
    		
    		$z = $v[$n];
    		$y = $v[0];
    		$delta = 0x9E3779B9;
    		$q = floor(6 + 52 / ($n + 1));
    		$sum = self::int32($q * $delta);
    		while ($sum != 0) {
    			$e = $sum >> 2 & 3;
    			for ($p = $n; $p > 0; $p--) {
    				$z = $v[$p - 1];
    				$mx = self::int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ self::int32(
    					($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
    				$y = $v[$p] = self::int32($v[$p] - $mx);
    			}
    			$z = $v[$n];
    			$mx = self::int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ self::int32(
    				($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
    			$y = $v[0] = self::int32($v[0] - $mx);
    			$sum = self::int32($sum - $delta);
    		}
    		return self::long2str($v, true);
    	}
    
    	/**
    	 * 长整型转换为字符串
    	 *
    	 * @param long $v
    	 * @param boolean $w
    	 * @return string
    	 */
    	private function long2str($v, $w) {
    		$len = count($v);
    		$s = array();
    		for ($i = 0; $i < $len; $i++)
    			$s[$i] = pack("V", $v[$i]);
    		return $w ?

    substr(join('', $s), 0, $v[$len - 1]) : join('', $s); } /** * 字符串转化为长整型 * * @param string $s * @param boolean $w * @return Ambigous <multitype:, number> */ private function str2long($s, $w) { $v = unpack("V*", $s . str_repeat("", (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 <= -2147483649) $n += 4294967296; return (int) $n; } }


    onethink中间user模块的相应变化

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    SpringCloud 学习笔记(7)路由网关Zuul
    调用数据库中某特定项的方法
    节点在TreeView中无限添加,无刷新实现父节点选中,子节点同时选中
    jQuery formValidator 表单校验插件4.1.1高仿网易邮箱注册页面(已发演示链接)
    jQuery formValidator 4.0 表单验证插件(正式版)
    jQuery formValidator表单验证插件4.1.0 下载 演示 文档 可换肤 代码生成器
    jQuery formValidator表单验证插件3.5a 版本发布,适合jQuery1.3.2类库
    武林英雄辅助工具
    jQuery formValidator表单验证插件4.1.3提供下载
    jQuery formValidator4.0.1 表单校验插件更新日志(已提供下载)
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4740400.html
Copyright © 2020-2023  润新知