Issue 19: Example error
Status:  Fixed
Owner: ----
Closed:  Nov 2010
Reported by nielsba...@gmail.com, Nov 21, 2010
Hi,

I had difficulties with your example.php, because the openId provider that I was using as test (Hyves.nl) uses POST callbacks rather than GET. So your login example failed because it only looks at $_GET['openid_mode']. I fixed this, and I also merged the Google example into the regular example (might be more convenient for most people). You might not agree with the latter, however here is the code.

Thanks!
Niels

>---



try {
	$openid_mode = '';
	if (isset($_GET['openid_mode']) ){
		$openid_mode=$_GET['openid_mode'];
	} else if (isset($_POST['openid_mode'])) {
		$openid_mode=$_POST['openid_mode'];
	} 
    if($openid_mode=='' ) {
        if (isset($_POST['openid_identifier'])) {
            $openid = new LightOpenID;
			
			// Google only provider
			if (strpos($_POST['openid_identifier'],'google')!==FALSE || 
				strpos($_POST['openid_identifier'],'gmail')!==FALSE) {
				$openid->identity = 'https://www.google.com/accounts/o8/id';
			} else {
				$openid->identity = $_POST['openid_identifier'];
			}
            header('Location: ' . $openid->authUrl());
        }
?>
<form action="" method="post">
    OpenID: <input type="text" name="openid_identifier" /> <button>Submit</button>
</form>
<?php
    } elseif ($openid_mode == 'cancel'   ) {
        echo 'User has canceled authentication!';
    } else {
        $openid = new LightOpenID;
        echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
    }
} catch(ErrorException $e) {
    echo $e->getMessage();
}


Nov 22, 2010
Project Member #1 mewp...@gmail.com
You've broken the support for google profiles while merging the examples (urls like http://google.com/profiles/login). Don't do things like guessing what a openid identifier might be -- it's wrong, and can easily cause problems. And even if it doesn't, it's confusing to the user, because it works differently on different websites. That's one of the reasons why google-example.php has a button.

That said, I'll push a commit soon, that fixes it.
Status: Started
Nov 22, 2010
Project Member #2 mewp...@gmail.com
I have added $openid->mode that returns openid.mode either from $_GET or $_POST, depending on where it's avaiable.
Status: Fixed
Nov 24, 2010
#3 nielsba...@gmail.com
That's cool, thanx!