Main
Latest
- Custom Muti Widgets
- Google Social Graph API and PHP 5.2
- Google AJAX Feed API Muti Example
- Gnip API Changes
- Google Maps and Geolocation
- oEmbed, flickr and starstar
- Petition Against Public Holidays
- Good Morning
- Django Apache Configuration
- Raising funds for Autism Western Cape
Archives
- June 2004
- July 2004
- August 2004
- September 2004
- October 2004
- November 2004
- December 2004
- January 2005
- February 2005
- March 2005
- April 2005
- May 2005
- June 2005
- July 2005
- August 2005
- September 2005
- October 2005
- November 2005
- December 2005
- January 2006
- February 2006
- March 2006
- April 2006
- May 2006
- June 2006
- July 2006
- August 2006
- September 2006
- November 2006
- December 2006
- January 2007
- February 2007
- March 2007
- April 2007
- May 2007
- June 2007
- July 2007
- August 2007
- September 2007
- October 2007
- November 2007
- December 2007
- January 2008
- February 2008
- March 2008
- April 2008
- May 2008
- June 2008
- July 2008
- August 2008
- September 2008
- October 2008
- November 2008
- December 2008
- January 2009
Zend Framework Google Login Example
Here is an example of how you can use Zend Framework to allow your users to log into your site using their Google Account access details.
<?php
session_start();
$email = isset($_REQUEST['email']) ? $_REQUEST['email'] : null;
$password = isset($_REQUEST['password']) ? $_REQUEST['password'] : null;
$captchaToken = isset($_REQUEST['captchatoken']) ? $_REQUEST['captchatoken'] : null;
$captchaText = isset($_REQUEST['captchatext']) ? $_REQUEST['captchatext'] : null;
if ($email && $password) {
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
try {
$client = Zend_Gdata_ClientLogin::getHttpClient($email, $password, 'xapi', null, 'Zend-ZendFramework', $captchaToken, $captchaText);
$_SESSION['email'] = $email;
} catch (Zend_Gdata_App_CaptchaRequiredException $e) {
$captchaToken = $e->getCaptchaToken();
$captchaUrl = $e->getCaptchaUrl();
} catch (Zend_Gdata_App_AuthException $e) {
$error = $e->getMessage();
}
}
if (isset($_SESSION['email'])) {
header('Location: profile');
exit;
}
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Zend Framework Google Login Example</title>
</head>
<body>
<h1>Zend Framework Google Login Example</h1>
<?php if (isset($error)): ?>
<p><?php echo htmlspecialchars($error); ?></p>
<?php endif; ?>
<form method="post">
<p><label for="email">Email:</label> <input id="email" name="email" type="text" value="<?php echo htmlspecialchars($email); ?>"></p>
<p><label for="password">Password:</label> <input id="password" name="password" type="password"></p>
<?php if (isset($captchaUrl)): ?>
<div><input type="hidden" name="captchatoken" value="<?php echo htmlspecialchars($captchaToken); ?>"></div>
<p><img src="<?php echo htmlspecialchars($captchaUrl); ?>" alt=""></p>
<p><label for="captchatext">Text:</label> <input id="captchatext" name="captchatext" type="text"></p>
<?php endif; ?>
<p><button type="submit">Login</button></p>
</form>
</body>
</html>
I just don't want to have my password travel through somebody else's system. Surely there must be a better way? Can't we just do it like with Google App Engine?
Copyright © 2004-2009 Charl van Niekerk. All articles are released under the Creative Commons Attribution 2.5 South Africa licence, unless where otherwise stated.


3 Comments
Comment by
calisza on Saturday, September 27, 2008 6:58:00 AM
Good example of what the Zend Framework can do. wd!
Comment by
freebird on Saturday, September 27, 2008 9:13:00 AM
even i am looking for the same :-) not able to find anything till now.
Probably we can try modifying Oauth code available for cakephp
Comment by
Charl van Niekerk on Saturday, September 27, 2008 8:26:00 PM
Thanks guys. Yeah the ZF GData PHP API libraries are even credited on Google's site.
Post a Comment