什么是php中的函数redirect()

时间:2011-11-09 10:10:32

标签: php codeigniter

我使用代码连接gmail并获取我的朋友列表。在该代码中有一个函数调用

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

我搜索了函数redirect(),但没有在php手册中找到它。它是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');

}

4 个答案:

答案 0 :(得分:2)

它是CodeIgniter URL帮助程序的一部分。参见:

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

来自文档:

  

指定URI的“标头重定向”。如果指定将构建链接的完整站点URL,但对于本地链接,只需将URI段提供给要指向的控制器即可创建链接。该函数将根据您的配置文件值构建URL。

答案 1 :(得分:1)

正如你所说,它不是一个内置函数,所以我们不知道它应该是什么样子。 但是,考虑到名称,我猜它应该是这样的:

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

由于发送Location: {ur}标头会将您的网页重定向到另一个网页。

答案 2 :(得分:0)

使用headerhttp://php.net/manual/en/function.header.php

header('Location: urlOfDestination');

答案 3 :(得分:0)

这可能是用户定义的功能。它可能与header()密切配合,因此名称,第一个参数是要重定向到的页面,第二个参数是告诉函数它确实是重定向到location。只需查看标题功能。