How to create google login on my site with openid in 5 min

August 21, 2013

As always we go straight to coding.

Download how-to-create-google-login-on-my-site-with-openid-in-5-min.zip

mode) {
		// the google openid url
		$openid->identity = 'https://www.google.com/accounts/o8/id';

		// information for for the user
		$openid->required = array('contact/email', 'namePerson/first', 'namePerson/last');

		// redirect to google
		header('Location: ' . $openid -> authUrl());
	} elseif ($openid->mode == 'cancel') {
		// user cancel the login
		// redirect may be ?
	} else {
		if ($openid->validate()) {
			// user logged in
			$d = $openid->getAttributes();

			$first_name = $d['namePerson/first'];
			$last_name = $d['namePerson/last'];
			$email = $d['contact/email'];

			// do your login

		} else {
			//user is not logged in
		}
	}
} catch(Exception $e) {
	// something went wrong
	echo $e->getMessage();
	exit;
}

Simple as that.

Suggestions or problems ? Write a comment.

tags: , ,
posted in how to ?, php by Ivan Gospodinow

Follow comments via the RSS Feed | Leave a comment | Trackback URL

Leave Your Comment


Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /home/c2kblate/sites/ivangospodinow.com/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048
 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org