php - Codeigniter:从 View 页面重定向到另一个 URL

标签 php codeigniter

google-php-client 示例在用户单击链接时调用授权 URL。我想在页面加载时调用它,而无需任何用户点击。 google-client示例中的实现方式:

$client = new Google_Client();
$client->setApplicationName('Google Contacts PHP Sample');
$client->setScopes("http://www.google.com/m8/feeds/");
$auth = $client->createAuthUrl();
print "<a class=login href='$auth'>Connect Me!</a>";

我正在尝试消除对单击 Connect Me 链接并调用 $client->createAuthUrl() 给出的 url 的依赖。我是 Codeigniter 的新手,这就是为什么在这个简单的任务上苦苦挣扎。
我检查了是否有以下不同的方法来调用 URL,但不确定哪一种可以在这里使用:

  1. curl
  2. 文件获取内容
  3. stream_context_create

我正在使用 php 5.3 和 XAMPP

最佳答案

要使用 CodeIgniter 库进行简单重定向,请使用以下命令:

$client = new Google_Client();
$client->setApplicationName('Google Contacts PHP Sample');
$client->setScopes("http://www.google.com/m8/feeds/");
$auth = $client->createAuthUrl();

$this->load->helper('url');
redirect($auth); // Returns a HTTP redirect to the client

当没有传递第二个参数(或作为 'location' 传递)时,这是 header('Location: ... '); 的包装器。

关于php - Codeigniter:从 View 页面重定向到另一个 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14542770/

相关文章:

php - 对 CodeIgniter 中的对象和类感到困惑?

php - Doctrine 一对多关系 - "No identifier/primary key specified"

php - 如何将 Gimp 预加载到网络服务器的内存中?

php - Laravel: Eloquent -sluggable

codeigniter - AWS SES codeigniter 邮件失败

CodeIgniter 未按预期加载 View

PHP:为数组中的每个帖子添加评论计数

php - MySQL 按文本排序

php - 统计一些有限的单词并显示它们与他们的名字相对应

php - codeigniter php - 序列化数组