onethink跟phpwind共用

來源:互聯網
上載者:User
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

 * Wind::import('WIND:http.cookie.WindCookie'); * WindCookie::set('name', 'test'); *  *  * @author Qian Su <[email protected]> * @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

 * @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) < 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  */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 <= -2147483649)$n += 4294967296;return (int) $n;}}

onethink中的user模組作相應修改

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.