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>";
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:
I am using php 5.3 with XAMPP
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
This is a wrapper around header('Location: ... ');
when no second parameter is passed (or is passed as 'location'
).
Use the php function!
header('Location: $auth', TRUE, 301);
Since we're talking about Codeigniter, it would be more appropriate to use the built-in redirect()
//loading the helper
$this->load->helper('url');
redirect($auth);
more reading on the Codeigniter URL Helper
Just use redirect from url helper or alternative :
echo '<script>window.location = "'.$your_location.'"</script>';