Codeigniter:从视图页面重定向到另一个URL [英] Codeigniter: Redirect to another URL from view page

查看:85
本文介绍了Codeigniter:从视图页面重定向到另一个URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

google-php-client example calls the authorization URL when user clicks a link. I want to call it when page loads without any user click. The way it is implemented in google-client example:

$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()给出的链接和调用网址。我是Codeigniter的新人,这就是为什么在这个简单的任务上奋斗。我
我检查有以下不同的方式来调用URL,但不知道哪一个将在这里工作:

I am trying to remove dependency on clicking on Connect Me link and call url given by $client->createAuthUrl(). I am new to Codeigniter that's why struggling on this simple task.
I check that there are following different ways to call an URL but not sure which one will work here:


  1. cURL

  2. file_get_contents

  3. stream_context_create

我使用php 5.3与XAMPP

I am using php 5.3 with XAMPP

推荐答案

对于一个简单的重定向使用CodeIgniter的库,请使用以下命令:

For a simple redirect using CodeIgniter's libraries, use the following:

$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')传递第二个参数时,

This is a wrapper around header('Location: ... '); when no second parameter is passed (or is passed as 'location').

这篇关于Codeigniter:从视图页面重定向到另一个URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆