Note that there are some explanatory texts on larger screens.

plurals
  1. POHas any one got class.openid.php working with google openID?
    primarykey
    data
    text
    <p>I am trying to study <code>class.openid.php</code> because it is simpler and smaller than <a href="http://code.google.com/p/lightopenid/" rel="nofollow"><br> lightopenid</a>. for my purposes 200 lines do matter. But <code>class.openid.php</code> does not work with google openID <code>https://www.google.com/accounts/o8/id</code>, prints to me such error:</p> <pre><code>ERROR CODE: OPENID_NOSERVERSFOUND ERROR DESCRIPTION: Cannot find OpenID Server TAG on Identity page. </code></pre> <p>is it possible to make class.openid.php (any version) work with google openID and how to do such thing?</p> <p><code>class.openid.php</code> can be taken <a href="http://www.phpclasses.org/package/3290-PHP-Authenticate-users-with-OpenID-single-sign-on.html" rel="nofollow">here</a> but it did not worked for me out of the box so I had to find all <code>&lt;?</code> and replace tham with <code>&lt;?php</code> in case someone would like to see code I've got:</p> <p>html interface page:</p> <pre><code>&lt;?php require('class.openid.v3.php'); if ($_POST['openid_action'] == "login"){ // Get identity from user and redirect browser to OpenID Server $openid = new SimpleOpenID; $openid-&gt;SetIdentity($_POST['openid_url']); $openid-&gt;SetTrustRoot('http://' . $_SERVER["HTTP_HOST"]); $openid-&gt;SetRequiredFields(array('email','fullname')); $openid-&gt;SetOptionalFields(array('dob','gender','postcode','country','language','timezone')); if ($openid-&gt;GetOpenIDServer()){ $openid-&gt;SetApprovedURL('http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PATH_INFO"]); // Send Response from OpenID server to this script $openid-&gt;Redirect(); // This will redirect user to OpenID Server }else{ $error = $openid-&gt;GetError(); echo "ERROR CODE: " . $error['code'] . "&lt;br&gt;"; echo "ERROR DESCRIPTION: " . $error['description'] . "&lt;br&gt;"; } exit; } else if($_GET['openid_mode'] == 'id_res'){ // Perform HTTP Request to OpenID server to validate key $openid = new SimpleOpenID; $openid-&gt;SetIdentity($_GET['openid_identity']); $openid_validation_result = $openid-&gt;ValidateWithServer(); if ($openid_validation_result == true){ // OK HERE KEY IS VALID echo "VALID"; }else if($openid-&gt;IsError() == true){ // ON THE WAY, WE GOT SOME ERROR $error = $openid-&gt;GetError(); echo "ERROR CODE: " . $error['code'] . "&lt;br&gt;"; echo "ERROR DESCRIPTION: " . $error['description'] . "&lt;br&gt;"; }else{ // Signature Verification Failed echo "INVALID AUTHORIZATION"; } }else if ($_GET['openid_mode'] == 'cancel'){ // User Canceled your Request echo "USER CANCELED REQUEST"; } ?&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;OpenID Example&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;fieldset id="openid"&gt; &lt;legend&gt;OpenID Login&lt;/legend&gt; &lt;form action="&lt;?php echo 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PATH_INFO"]; ?&gt;" method="post" onsubmit="this.login.disabled=true;"&gt; &lt;input type="hidden" name="openid_action" value="login"&gt; &lt;div&gt;&lt;input type="text" name="openid_url" class="openid_login"&gt;&lt;input type="submit" name="login" value="login &amp;gt;&amp;gt;"&gt;&lt;/div&gt; &lt;div&gt;&lt;a href="http://www.myopenid.com/" class="link" &gt;Get an OpenID&lt;/a&gt;&lt;/div&gt; &lt;/form&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;div style="margin-top: 2em; font-family: arial; font-size: 0.8em; border-top:1px solid gray; padding: 4px;"&gt;Sponsored by: &lt;a href="http://www.fivestores.com"&gt;FiveStores&lt;/a&gt; - get your free online store; includes extensive API for developers; &lt;i style="color: gray;"&gt;integrated with &lt;a href="http://en.wikipedia.org/wiki/OpenID"&gt;OpenID&lt;/a&gt;&lt;/i&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and php class</p> <pre><code>&lt;?php /* FREE TO USE Under License: GPLv3 Simple OpenID PHP Class Some modifications by Eddie Roosenmaallen, eddie@roosenmaallen.com */ class SimpleOpenID{ var $openid_url_identity; var $URLs = array(); var $error = array(); var $fields = array( 'required' =&gt; array(), 'optional' =&gt; array(), ); function SimpleOpenID(){ if (!function_exists('curl_exec')) { die('Error: Class SimpleOpenID requires curl extension to work'); } } function SetOpenIDServer($a){ $this-&gt;URLs['openid_server'] = $a; } function SetTrustRoot($a){ $this-&gt;URLs['trust_root'] = $a; } function SetCancelURL($a){ $this-&gt;URLs['cancel'] = $a; } function SetApprovedURL($a){ $this-&gt;URLs['approved'] = $a; } function SetRequiredFields($a){ if (is_array($a)){ $this-&gt;fields['required'] = $a; }else{ $this-&gt;fields['required'][] = $a; } } function SetOptionalFields($a){ if (is_array($a)){ $this-&gt;fields['optional'] = $a; }else{ $this-&gt;fields['optional'][] = $a; } } function SetIdentity($a){ // Set Identity URL if ((stripos($a, 'http://') === false) &amp;&amp; (stripos($a, 'https://') === false)){ $a = 'http://'.$a; } $this-&gt;openid_url_identity = $a; } function GetIdentity(){ // Get Identity return $this-&gt;openid_url_identity; } function GetError(){ $e = $this-&gt;error; return array('code'=&gt;$e[0],'description'=&gt;$e[1]); } function ErrorStore($code, $desc = null){ $errs['OPENID_NOSERVERSFOUND'] = 'Cannot find OpenID Server TAG on Identity page.'; if ($desc == null){ $desc = $errs[$code]; } $this-&gt;error = array($code,$desc); } function IsError(){ if (count($this-&gt;error) &gt; 0){ return true; }else{ return false; } } function splitResponse($response) { $r = array(); $response = explode("\n", $response); foreach($response as $line) { $line = trim($line); if ($line != "") { list($key, $value) = explode(":", $line, 2); $r[trim($key)] = trim($value); } } return $r; } function OpenID_Standarize($openid_identity = null){ if ($openid_identity === null) $openid_identity = $this-&gt;openid_url_identity; $u = parse_url(strtolower(trim($openid_identity))); if (!isset($u['path']) || ($u['path'] == '/')) { $u['path'] = ''; } if(substr($u['path'],-1,1) == '/'){ $u['path'] = substr($u['path'], 0, strlen($u['path'])-1); } if (isset($u['query'])){ // If there is a query string, then use identity as is return $u['host'] . $u['path'] . '?' . $u['query']; }else{ return $u['host'] . $u['path']; } } function array2url($arr){ // converts associated array to URL Query String if (!is_array($arr)){ return false; } $query = ''; foreach($arr as $key =&gt; $value){ $query .= $key . "=" . $value . "&amp;"; } return $query; } function CURL_Request($url, $method="GET", $params = "") { // Remember, SSL MUST BE SUPPORTED if (is_array($params)) $params = $this-&gt;array2url($params); $curl = curl_init($url . ($method == "GET" &amp;&amp; $params != "" ? "?" . $params : "")); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_HTTPGET, ($method == "GET")); curl_setopt($curl, CURLOPT_POST, ($method == "POST")); if ($method == "POST") curl_setopt($curl, CURLOPT_POSTFIELDS, $params); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); if (curl_errno($curl) == 0){ $response; }else{ $this-&gt;ErrorStore('OPENID_CURL', curl_error($curl)); } return $response; } function HTML2OpenIDServer($content) { $get = array(); // Get details of their OpenID server and (optional) delegate preg_match_all('/&lt;link[^&gt;]*rel=[\'"]openid.server[\'"][^&gt;]*href=[\'"]([^\'"]+)[\'"][^&gt;]*\/?&gt;/i', $content, $matches1); preg_match_all('/&lt;link[^&gt;]*href=\'"([^\'"]+)[\'"][^&gt;]*rel=[\'"]openid.server[\'"][^&gt;]*\/?&gt;/i', $content, $matches2); $servers = array_merge($matches1[1], $matches2[1]); preg_match_all('/&lt;link[^&gt;]*rel=[\'"]openid.delegate[\'"][^&gt;]*href=[\'"]([^\'"]+)[\'"][^&gt;]*\/?&gt;/i', $content, $matches1); preg_match_all('/&lt;link[^&gt;]*href=[\'"]([^\'"]+)[\'"][^&gt;]*rel=[\'"]openid.delegate[\'"][^&gt;]*\/?&gt;/i', $content, $matches2); $delegates = array_merge($matches1[1], $matches2[1]); $ret = array($servers, $delegates); return $ret; } function GetOpenIDServer(){ $response = $this-&gt;CURL_Request($this-&gt;openid_url_identity); list($servers, $delegates) = $this-&gt;HTML2OpenIDServer($response); if (count($servers) == 0){ $this-&gt;ErrorStore('OPENID_NOSERVERSFOUND'); return false; } if (isset($delegates[0]) &amp;&amp; ($delegates[0] != "")){ $this-&gt;SetIdentity($delegates[0]); } $this-&gt;SetOpenIDServer($servers[0]); return $servers[0]; } function GetRedirectURL(){ $params = array(); $params['openid.return_to'] = urlencode($this-&gt;URLs['approved']); $params['openid.mode'] = 'checkid_setup'; $params['openid.identity'] = urlencode($this-&gt;openid_url_identity); $params['openid.trust_root'] = urlencode($this-&gt;URLs['trust_root']); if (isset($this-&gt;fields['required']) &amp;&amp; (count($this-&gt;fields['required']) &gt; 0)) { $params['openid.sreg.required'] = implode(',',$this-&gt;fields['required']); } if (isset($this-&gt;fields['optional']) &amp;&amp; (count($this-&gt;fields['optional']) &gt; 0)) { $params['openid.sreg.optional'] = implode(',',$this-&gt;fields['optional']); } return $this-&gt;URLs['openid_server'] . "?". $this-&gt;array2url($params); } function Redirect(){ $redirect_to = $this-&gt;GetRedirectURL(); if (headers_sent()){ // Use JavaScript to redirect if content has been previously sent (not recommended, but safe) echo '&lt;script language="JavaScript" type="text/javascript"&gt;window.location=\''; echo $redirect_to; echo '\';&lt;/script&gt;'; }else{ // Default Header Redirect header('Location: ' . $redirect_to); } } function ValidateWithServer(){ $params = array( 'openid.assoc_handle' =&gt; urlencode($_GET['openid_assoc_handle']), 'openid.signed' =&gt; urlencode($_GET['openid_signed']), 'openid.sig' =&gt; urlencode($_GET['openid_sig']) ); // Send only required parameters to confirm validity $arr_signed = explode(",",str_replace('sreg.','sreg_',$_GET['openid_signed'])); for ($i=0; $i&lt;count($arr_signed); $i++){ $s = str_replace('sreg_','sreg.', $arr_signed[$i]); $c = $_GET['openid_' . $arr_signed[$i]]; // if ($c != ""){ $params['openid.' . $s] = urlencode($c); // } } $params['openid.mode'] = "check_authentication"; $openid_server = $this-&gt;GetOpenIDServer(); if ($openid_server == false){ return false; } $response = $this-&gt;CURL_Request($openid_server,'POST',$params); $data = $this-&gt;splitResponse($response); if ($data['is_valid'] == "true") { return true; }else{ return false; } } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload