2011-11-09 27 views
-1

我使用代碼來連接Gmail並得到我的朋友列表。在該代碼中有我搜索的功能redirect()但在PHP手冊中沒有找到它的函數調用什麼是函數重定向()在PHP

redirect('https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token='. $oauth->rfc3986_decode($accrss_token['oauth_token']), 'location'); 

。它是在PHP中內置函數嗎?

第二個參數是'location'那個參數的用法是什麼?

這裏是它的使用功能:

public function connect_google($oauth=null){ 

if(!$oauth) 
{ 
    return null; 
} 
//create a gmailcontacts objects 
$getcontact = new GmailGetContacts(); 
$accrss_token = $getcontact->get_request_token($oauth, false, true, true); 

$this->ci->session->set_userdata('oauth_token', $accrss_token['oauth_token']); 
$this->ci->session->set_userdata('oauth_token_secret', $accrss_token['oauth_token_secret']); 
//redirect to google auth 
redirect('https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token='. $oauth->rfc3986_decode($accrss_token['oauth_token']), 'location'); 

} 

回答

2

它是CodeIgniter URL助手的一部分。請參閱:

http://codeigniter.com/user_guide/helpers/url_helper.html

從文檔:

難道一個 「頭重定向」 到指定的URI。如果您指定將構建鏈接的完整站點URL,但對於本地鏈接,只需將URI段提供給要指向的控制器即可創建鏈接。該函數將根據您的配置文件值構建URL。

1

正如你所說的,它不是一個內置的功能,所以我們不知道它應該看起來像。 但是,考慮到名字我想這應該是這樣的:

function redirect($url, $header) 
{ 
header("$header: $url"); 
} 

由於發送Location: {ur}頭將你的頁面重定向到另一個。

+0

我以爲這個函數在設置標題後會包含'exit'或'die'。也許它還包括檢查頭是否已經發送等,以改善錯誤處理。 –

0

它可能是用戶定義的函數。它可能與header()因此一起使用,因此名稱,第一個參數是要重定向到的頁面,第二個參數是告訴函數,它確實是重定向到location。只需檢查標題功能。