I'm trying to validate a user with LightOpenID and what I also need is to get their profile name but I'm having trouble getting a session variable $_SESSION['profile']
to get the form post $_POST['profile']
to store the information before the page is redirected to google. I'm not sure if this is the way to go about this but I can't think of any other way to tie a user to my database besides doing this. Here's the code
<?php
session_start();
# Logging in with Google accounts requires setting special identity, so this example shows how to do it.
require 'openid.php';
try
{
$openid = new LightOpenID('http://www.some_site.com');
if(!$openid->mode) {
if(isset($_GET['login']))
{
$_SESSION['profile'] = $_POST['profile'];
$openid->identity = 'https://www.google.com/accounts/o8/id';
header('Location: ' . $openid->authUrl());
}
?>
<form action="?login" method="post">
<table border="0">
<tr><td colspan=2><h1>Login</h1></td></tr>
<tr><td>Username:</td><td>
<input type="text" name="profile" maxlength="40">
</td></tr>
</table>
<button>Login with Google</button>
</form>
<?php
}
elseif($openid->mode == 'cancel')
{
echo 'User has canceled authentication!';
}
else
{
echo $_SESSION['profile'];
echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
}
}
catch(ErrorException $e)
{
echo $e->getMessage();
}
Doesn't show email after login though.
<?php
require 'openid.php';
$openid = new LightOpenID('http://www.some_site.com');
if (!$openid->mode) {
$openid->identity = 'https://www.google.com/accounts/o8/id';
$openid->required = array('contact/email');
header('Location: ' . $openid->authUrl());
} else {
if ($openid->validate()) {
$attributes = $openid->getAttributes();
$google_email = $attributes['contact/email'];
echo $google_email."<br />";
echo "<pre>" . print_r($_GET, true) . "</pre>";
//header("Location: " . SITEURL);
}
}
?>