Onethink and phpwind are shared, and onethinkphpwind
Install the onethink and phpwind databases together and use the common table prefix.
Point the onethink member table to the phpwind user table.
The following figure shows how to install onethink in the root directory and phpwind In the bbs directory.
Modify the is_login function in onethink
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 ); /* log on to the SESSION and 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 ;}*/}
Add Org/util/pw. class. php and Org/WindCookie. class. php to the think library.
1. WindCookie. class. php
<? When using phpnamespace Org;/*** cookie operation class **, all methods in this class are used statically: * <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 08: 02: 25Z yishuo $ * @ package http * @ subpackage cookie */class WindCookie {/*** set cookie ** @ param string $ name cookie name * @ param string $ value cookie value, the default value is null * @ param boolean $ encode whether to use MIME base64 to encode the data. The default value is false, that is, no encoding * @ param string | int $ expires expiration time, the default value is null, indicating that the session cookie will be destroyed as the session ends * @ Param string $ path: the path where the cookie is saved. If the default value is null, the default * @ param string $ domain cookie is used, if the default value is null, * @ param boolean $ secure is not set to secure connections. If the default value is false, the secure link * @ param boolean $ httponly is not used to access data through client scripts, the default value is false. That is, the client script can access the cookie * @ return boolean. If the value is set successfully, true is returned. If the value fails, 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 = base64_encode ($ value); $ path = $ path? $ Path: '/'; setcookie ($ name, $ value, $ expires, $ path, $ domain, $ secure, $ httponly); return true ;} /*** delete cookie Based on the cookie name ** @ param string $ name cookie name * @ return boolean return true */public static function delete ($ name) {if (self: exist ($ name) {self: set ($ name, ''); unset ($ _ COOKIE [$ name]);} return true;}/*** get the cookie value of the specified name ** @ param string $ name cookie name * @ param boolean $ whether dencode has performed the cookie value Decoding. The default value is false. * @ return mixed is not required to be decoded. If the result is obtained successfully, the stored cookie value is returned. If the result fails to be obtained, 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;}/*** remove all cookies ** @ return boolean return true */public static function deleteAll () {$ _ COOKIE = array (); return true;}/*** determines whether a cookie exists ** @ param string $ name cookie name * @ return boolean returns false if it does not exist, otherwise, true */public static function exist ($ name) {return isset ($ _ COOKIE [$ name]);} is returned.
2. pw. class. php
<? Phpnamespace Org \ util; use Org \ WindCookie;/*** tool library *** @ author Jianmin Chen <sky_hold@163.com> * @ copyright©2003-2103 phpwind.com * @ license http://www.phpwind.com * @ version $ Id: Pw. php 28776 08: 46: 10Z jieyin $ * @ package library */class Pw {/*** get the cookie value of the specified name ** @ param string $ name cookie name * @ param string $ pre cookie prefix, the default value is null. No prefix * @ return boolean */public static function getCookie ($ name) {$ site = C ('bbs _ SITE_SET '); $ pre = $ site ['cookie. pre ']; $ pre & $ name = $ pre. '_'. $ name; return Wi NdCookie: get ($ name);}/*** set cookie ** @ param string $ name cookie name * @ param string $ value cookie value, the default value is null * @ param string | int $ expires. The default value is null, indicating the session cookie. When the session ends, the * @ param string $ pre cookie prefix will be destroyed, the default value is null. No prefix * @ 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);}/*** encryption method ** @ 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 ));} /*** Decryption Method ** @ 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);}/*** encrypted password storage ** @ param string $ pwd * @ return string */public static function getPwdCode ($ pwd) {$ site = C ('bbs _ SITE_SET '); return md5 ($ pwd. $ site ['hash']);} pub Lic 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 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 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 );} /*** convert a long integer to a string ** @ 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 );} /*** convert a string to a long integer ** @ param string $ s * @ param boolean $ w * @ return Ambigous <multitype :, number> */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 ;}}
Modify the user Module in onethink