-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-google.php
46 lines (43 loc) · 1.29 KB
/
example-google.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
# Logging in with Google accounts requires setting special identity, so this example shows how to do it.
require_once 'openid.php';
//start the session
session_start();
try {
# Change 'localhost' to your domain name.
if (strpos($_SERVER['HTTP_HOST'],'localhost') !== false){
//local version
$openid_google = new LightOpenID('localhost:8888');
} else{
//remote version
$openid_google = new LightOpenID('mike-eng.com');
}
if(!$openid_google->mode) {
if(isset($_GET['login'])) {
$openid_google->identity = 'https://www.google.com/accounts/o8/id';
$openid_google->required = array('contact/email');
header('Location: ' . $openid_google->authUrl());
}
?>
<!--
<form action="?login" method="post">
<button>Login with Google</button>
</form>
-->
<?php
} elseif($openid_google->mode == 'cancel') {
echo 'User has canceled authentication!';
} else {
//echo 'User ' . ($openid_google->validate() ? $openid_google->identity . ' has ' : 'has not ') . 'logged in.';
$userinfo = $openid_google->getAttributes();
$email = $userinfo['contact/email'];
/*
echo '<br/>';
echo $email;
*/
//store username variable across pages
$_SESSION['email'] = $email;
}
} catch(ErrorException $e) {
echo $e->getMessage();
}