退出提示 「Access denied for agent changed」
排查思路:
這是與 uc 請求的時候出問題導致。具體報錯部分是 uc_server/mode/user.php 中的 function init_input 函數部分的 ,對 $agent 進行了判斷。
- if(($getagent
&& $getagent != $this->input['agent']) || (!$getagent
&& md5($_SERVER['HTTP_USER_AGENT']) != $agent)) { - exit('Access denied for agent changed');
- }
下
面我們來簡單分析下退出的時候是怎麼 uc 請求的,打開 class_member.php 找到 on_logout 函數部分
$ucsynlogout = $this->setting['allowsynlogin'] ? uc_user_synlogout() :
''; 這這麼一行代碼,這是判斷程序是否開啓了同步登錄。如果開啓了同步登錄 uc_user_synlogout() 會執行請求
接下來,分析下 uc_user_synlogout( 這些函數的調用是來自 loaducenter()) 。打開 uc_client/client.php
- function uc_user_synlogout() {
- if(@include UC_ROOT.'./data/cache/apps.php') {
- if(count($_CACHE['apps']) > 1) {
- $return = uc_api_post('user', 'synlogout', array());
- } else {
- $return = '';
- }
- }
- return $return;
- }
使用 post 方式請求 uc 。 大家可以閲讀下 uc_api_post 是怎麼處理的 。 uc_api_post 中有 uc_api_requestdata 這麼個函數
再看下 uc_api_input 函數。這個函數就是對輸入內容進行處理 使用 uc_authcode 進行加密處理,其中的 UC_key
是咱們熟悉的 config_ucenter.php 中的 UC_KEY 。 到此,大家應該對請求部分大體上有個瞭解,下面我們來看
uc_server 端的接收
我們看到 uc_api_requestdata 函數中的部分
- $post = "m=$module&a=$action&inajax=2&release=".UC_CLIENT_RELEASE."&input=$input&appid=".UC_APPID.$extra;
然後使用 uc_fopen2(此函數原理,大家自行閲讀在此不做介紹) 去請求。
打開 uc_server/index.php 文件
- if(in_array($m,
array('app', 'frame', 'user', 'pm', 'pm_client', 'tag', 'feed',
'friend', 'domain', 'credit', 'mail', 'version'))) { - if(file_exists(UC_ROOT.RELEASE_ROOT."control/$m.php")) {
- include UC_ROOT.RELEASE_ROOT."control/$m.php";
- } else {
- include UC_ROOT."control/$m.php";
- }
- $classname = $m.'control';
- $control = new $classname();
- $method = 'on'.$a;
- if(method_exists($control, $method) && $a{0} != '_') {
- $data = $control->$method();
- echo is_array($data) ? $control->serialize($data, 1) : $data;
- exit;
- } elseif(method_exists($control, '_call')) {
- $data = $control->_call('on'.$a, '');
- echo is_array($data) ? $control->serialize($data, 1) : $data;
- exit;
- } else {
- exit('Action not found!');
- }
- }
會
對用請求的內容進行處理,然後找到對應的模塊就行響應請求。 退出的時候,程序會進入到 uc_server/model/base.php 文件中的
init_input() 函數 $input = $this->authcode($input, 'DECODE',
$this->app['authkey']); 如果這裏的解壓有問題。那麼,就會導致出現 『Access denied for agent
changed』 這樣的錯誤。
解決方法:
現在我們來分析下原因:
在這個請求的過程中,牽涉的到加密和解密兩個部分,如果兩個其中有一方的 key 不一樣都會導致出現問題,用户要仔細檢查
config_ucenter.php 中 UC_KEY 和 UC_APPID 是否與
uc_server/data/cache/apps.php 中的 authkey 和 appid(這裏 key 和 appid
有時候會出現與 ucenter 中心的不一樣問題,一般是文件權限導致) 是否對應。 其次,有時候
域名有 uc_api 中的 uc 訪問路徑有問題的時候,請配置下 config_ucenter.php 中的 UC_IP