国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

uc_client與ucenter通信原理

2024-08-30 19:06:54
字體:
來源:轉載
供稿:網友

以用戶登錄為例介紹,其它注銷,改密碼,消息,頭像,好友均類同.

1.從用戶xxx在某一應用程序的login.php,輸入用戶名,密碼講起。

先用uc_user_login函數到uc server驗證此用戶和密碼,如正確,則寫入session,寫入cookies,并更新應用程序會員表中的登錄ip,登錄時間。用戶感覺不到這個過程。

2.然后通過uc_user_synlogin通知uc server 用戶xxx登錄成功,這個過程可能使用ajax,用戶感覺不到通知過程。

3.uc server收到這個消息后,馬上命令手下,把xxx登錄的消息,像令牌環一樣,發給所有愿意接收(后臺中那個是否開啟同步登錄)這個消息的其它應用程序。其實就是帶參數訪問一下各應用程序的uc.php,用戶感覺不到這個過程。

4.各應用程序靠api下的uc.php來接收uc server發來的消息,并對uc server言聽計從,讓干什么就干什么。現在,收到讓xxx用戶在你的程序中登錄的命令,馬上執行。

并寫本應用程序的session,并且使用p3p, 寫入相同域或不同域的cookies.   用戶感覺不到這個過程。

5.最后所有和uc整合的程序,xxx均登錄成功。用戶從www.test.com/bbs登錄后, 跳到www.test.com/news同樣顯示登錄。因為bbs 和news系統在后臺均已登錄。

6.應用程序與uc server的會話結束。

得益于uc設計的精巧過程,整個過程,用戶完全感覺不到ucenter的存在.這是整合程序歷史上的創新。

以下為其中的一個例子:

Supesite的uc_client和ucenter登錄通信過程

1、登錄入口Index.php?action-login

  1. //系統頻道 
  2. if($_SGET['action'] != 'index') {      
  3. if(emptyempty($channels['menus'][$_SGET['action']]['upnameid']) && $channels['menus'][$_SGET['action']]['upnameid'] != 'news') { 
  4. $scriptfile = S_ROOT.'./'.$_SGET['action'].'.php'
  5. else { 
  6. $scriptfile = S_ROOT.'./news.php'
  7.      //echo   $scriptfile; 
  8. if(file_exists($scriptfile)) { 
  9. include_once($scriptfile); 
  10. exit(); 

登錄控制器:Login.php

登錄視圖:Site_login.html.php

提交登錄action:batch.login.php?action=login

2、登錄處理地址batch.login.php?action=login

include_once(S_ROOT.'./uc_client/client.php');

登錄操作及其中涉及到的一些函數:

$password = $_POST['password'];

$username = $_POST['username'];

去ucenter進行遠程登錄驗證

$ucresult = uc_user_login($username, $password, $loginfield == 'uid');

如果登錄成功,則查本地用戶信息,如果有更新本地信息,如果沒有插入新的用戶數據保持與ucenter進行同步,然后同步其他子系統登錄信息:

  1. $msg = $lang['login_succeed'].uc_user_synlogin($members['uid']); 
  2.  
  3. function uc_user_synlogin($uid) { 
  4. $uid = intval($uid); 
  5. $return = uc_api_post('user''synlogin'array('uid'=>$uid)); 
  6. return $return
  7.  
  8.  
  9. function uc_api_post($module$action$arg = array()) { 
  10. $s = $sep = ''
  11. foreach($arg as $k => $v) { 
  12. $k = urlencode($k); 
  13. if(is_array($v)) { 
  14. $s2 = $sep2 = ''
  15. foreach($v as $k2 => $v2) { 
  16. $k2 = urlencode($k2); 
  17. $s2 .= "$sep2{$k}[$k2]=".urlencode(uc_stripslashes($v2)); 
  18. $sep2 = '&'
  19. $s .= $sep.$s2
  20. else { 
  21. $s .= "$sep$k=".urlencode(uc_stripslashes($v)); 
  22. $sep = '&'
  23. $postdata = uc_api_requestdata($module$action$s); 
  24.  
  25. return uc_fopen2(UC_API.'/index.php', 500000, $postdata'', TRUE, UC_IP, 20); 
  26.  
  27.  
  28. function uc_api_requestdata($module$action$arg=''$extra='') { 
  29. $input = uc_api_input($arg); 
  30. $post = "m=$module&a=$action&inajax=2&release=".UC_CLIENT_RELEASE."&input=$input&appid=".UC_APPID.$extra
  31. return $post
  32.  
  33. function uc_api_url($module$action$arg=''$extra='') { 
  34. $url = UC_API.'/index.php?'.uc_api_requestdata($module$action$arg$extra); 
  35. return $url
  36.  
  37. function uc_api_input($data) { 
  38. $s = urlencode(uc_authcode($data.'&agent='.md5($_SERVER['HTTP_USER_AGENT'])."&time=".time(), 'ENCODE', UC_KEY)); 
  39. return $s
  40.  
  41.  
  42. function uc_fopen2($url$limit = 0, $post = ''$cookie = ''$bysocket = FALSE, $ip = ''$timeout = 15, $block = TRUE) { 
  43. $__times__ = isset($_GET['__times__']) ? intval($_GET['__times__']) + 1 : 1; 
  44. if($__times__ > 2) { 
  45. return ''
  46. $url .= (strpos($url'?') === FALSE ? '?' : '&')."__times__=$__times__"
  47. return uc_fopen($url$limit$post$cookie$bysocket$ip$timeout$block); 
  48.  
  49. function uc_fopen($url$limit = 0, $post = ''$cookie = ''$bysocket = FALSE, $ip = ''$timeout = 15, $block = TRUE) { 
  50. $return = ''
  51. $matches = parse_url($url); 
  52. !isset($matches['host']) && $matches['host'] = ''
  53. !isset($matches['path']) && $matches['path'] = ''
  54. !isset($matches['query']) && $matches['query'] = ''
  55. !isset($matches['port']) && $matches['port'] = ''
  56. $host = $matches['host']; 
  57. $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/'
  58. $port = !emptyempty($matches['port']) ? $matches['port'] : 80; 
  59. if($post) { 
  60. $out = "POST $path HTTP/1.0/r/n"
  61. $out .= "Accept: **/r/n"
  62. //$out .= "Referer: $boardurl/r/n"; 
  63. $out .= "Accept-Language: zh-cn/r/n"
  64. $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]/r/n"
  65. $out .= "Host: $host/r/n"
  66. $out .= "Connection: Close/r/n"
  67. $out .= "Cookie: $cookie/r/n/r/n"
  68. $fp = @fsockopen(($ip ? $ip : $host), $port$errno$errstr$timeout); 
  69. if(!$fp) { 
  70. return '';//note $errstr : $errno /r/n 
  71. else { 
  72. stream_set_blocking($fp$block); 
  73. stream_set_timeout($fp$timeout); 
  74. @fwrite($fp$out); 
  75. $status = stream_get_meta_data($fp); 
  76. if(!$status['timed_out']) { 
  77. while (!feof($fp)) { 
  78. if(($header = @fgets($fp)) && ($header == "/r/n" ||   $header == "/n")) { 
  79. break
  80.  
  81. $stop = false; 
  82. while(!feof($fp) && !$stop) { 
  83. $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit)); 
  84. $return .= $data
  85. if($limit) { 
  86. $limit -= strlen($data); 
  87. $stop = $limit <= 0; 
  88. @fclose($fp); 
  89. return $return

遠程同步登錄子系統操作之后:

  1. //顯示信息 
  2. function showmessage($message$url_forward=''$second=3, $vars=array()) { 
  3. global $_SGLOBAL$_SCONFIG$_SC$channels
  4.  
  5. if(emptyempty($_SGLOBAL['inajax']) && $url_forward && emptyempty($second)) { 
  6. //直接301跳轉 
  7. obclean(); 
  8. header("HTTP/1.1 301 Moved Permanently"); 
  9. header("Location: $url_forward"); 
  10. else { 
  11. if(!defined('IN_SUPESITE_ADMINCP')) { 
  12. $tpl_file = 'showmessage'
  13. $fullpath = 0; 
  14. include_once(S_ROOT.'./language/message.lang.php'); 
  15. if(!emptyempty($mlang[$message])) $message = $mlang[$message]; 
  16. else { 
  17. $tpl_file = 'admin/tpl/showmessage.htm'
  18. $fullpath = 1; 
  19. include_once(S_ROOT.'./language/admincp_message.lang.php'); 
  20. if(!emptyempty($amlang[$message])) $message = $amlang[$message]; 
  21.  
  22. if(isset($_SGLOBAL['mlang'][$message])) $message = $_SGLOBAL['mlang'][$message]; 
  23. foreach ($vars as $key => $val) { 
  24. $message = str_replace('{'.$key.'}'$val$message); 
  25. //顯示 
  26. obclean(); 
  27. if(!emptyempty($url_forward)) { 
  28. $second = $second * 1000; 
  29. $message .= "<script>setTimeout(/"window.location.href ='$url_forward';/", $second);</script><ajaxok>"
  30.  
  31. include template($tpl_file$fullpath); 
  32. ob_out(); 
  33. exit(); 

Supesite中的Common.php部分解讀:

1、define('S_ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);

dirname(__FILE__)

S_ROOT=E:/mydoc/supesite

2、error_reporting指令確定PHP錯誤報告敏感度的級別,一共有十三個預定的錯誤級別,每一個都唯一對應于應用程序或服務器功能。

D_BUG?error_reporting(7):error_reporting(E_ERROR);

1 E_ERROR 

2 E_WARNING 

4 E_PARSE 

8 E_NOTICE 

16 E_CORE_ERROR 

32 E_CORE_WARNING

3、$_SGLOBAL = $_SBLOCK   = $_SCONFIG = $_SHTML = $_DCACHE = $_SGET = array();

4、//基本文件

  1. if(!@include_once(S_ROOT.'./config.php')) { 
  2. header("Location: install/index.php");//安裝 
  3. exit(); 
  4. include_once(S_ROOT.'./function/common.func.php'); 
  5. @include_once(S_ROOT.'./data/system/config.cache.php'); 

5、PHP extract() 函數從數組中把變量導入到當前的符號表中。

$_SCONFIG = array_merge($_SSCONFIG, $_SC);//合并配置

extract($_SC);

6、函數:get_magic_quotes_gpc()

取得 PHP 環境變量 magic_quotes_gpc 的值。

語法: long get_magic_quotes_gpc(void);

返回值: 長整數

函數種類: PHP 系統功能

本函數取得 PHP 環境配置的變量 magic_quotes_gpc (GPC, Get/Post/Cookie) 值。返回 0 表示關閉本功能;返回 1 表示本功能打開。當 magic_quotes_gpc 打開時,所有的 ' (單引號), " (雙引號), / (反斜線) and 空字符會自動轉為含有反斜線的溢出字符。

7、過濾’單引號

  1. function saddslashes($string) { 
  2. if(is_array($string)) { 
  3. foreach($string as $key => $val) { 
  4. $string[$key] = saddslashes($val); 
  5. else { 
  6. $string = addslashes($string); 
  7. return $string

addslashes()函數的作用是:使用反斜線引用字符串。

8、strlen()函數的作用:取字符串的長度

9、

  1. foreach($_COOKIE as $key => $val) { 
  2. if(substr($key, 0, $prelength) == $_SC['cookiepre']) { 
  3. $_SCOOKIE[(substr($key$prelength))] = emptyempty($magic_quote) ? saddslashes($val) : $val

10、getenv

取得系統的環境變量

語法: string getenv(string varname);

11、php strcasecmp()函數

strcasecmp()函數的作用是:對兩個字符串進行比較。

12、preg_match

13、ob_start 打開緩沖區

14、preg_replace執行正則表達式的搜索和替換

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 治多县| 旬阳县| 满洲里市| 晋宁县| 耿马| 镇远县| 邹平县| 牙克石市| 衡阳市| 安达市| 昆明市| 英山县| 乌兰县| 永善县| 扎兰屯市| 新乐市| 赣榆县| 汤原县| 博野县| 九寨沟县| 北海市| 扬中市| 玉树县| 凌云县| 绥中县| 黄平县| 公安县| 易门县| 兰州市| 秀山| 都安| 阳城县| 永泰县| 靖宇县| 黎城县| 台前县| 乐山市| 蕲春县| 延安市| 墨脱县| 陆河县|