मुझे LightOpenID नामक एक छोटी ओपनआईडी-लाइब्रेरी में समस्याएं आ रही हैं। मैं लगभग सभी प्रदाताओं को प्रमाणित कर सकता हूं, लेकिन मुझे नहीं पता कि प्रदाता से डेटा कैसे प्राप्त किया जाए। मुझे केवल ऐरे(), eaven प्रिंट_आर() के साथ मिलता है।PHP: LightOpenID, प्रदाता से खाता डेटा कैसे प्राप्त करें?
उत्तर
$openid->validate()
के बाद आपको getAttributes()
पर कॉल करने की आवश्यकता है।
याद रखें:
ध्यान दें कि यह गारंटी नहीं है कि आवश्यक/वैकल्पिक पैरामीटर के किसी भी वर्तमान
मैंने अभी ऐसा किया है: http://pastebin.com/ULsLvhxp तो ईमेल प्रदर्शित करने के लिए, क्या मैं $ foo ['ईमेल'] का उपयोग करता हूं? – Pwntus
यह '$ foo ['contact/email'] होगा - दस्तावेज़ों के अनुसार, गुणों को एएक्स प्रारूप में मैप किया गया है। – Pete
इसके अलावा, '$ openid-> आवश्यक = सरणी (' संपर्क/ईमेल '); ** ** ** $ openid-> मान्य() ' – Pete
यह वह जगह है तो मैं इसका उपयोग किया जाएगा। फ़ोल्डर lightopenid में यह openid.php फ़ाइल है। कक्षा में निम्नलिखित अतिरिक्त कार्य करना -
class LightOpenID
{
public $returnUrl
, $required = array()
, $optional = array()
, $verify_peer = null
, $capath = null
, $cainfo = null;
// these are the variables which store the data about the user...
public function ret_fname() { return $this->data['openid_ext1_value_namePerson_first']; }
public function ret_lname() { return $this->data['openid_ext1_value_namePerson_last']; }
public function ret_email() { return $this->data['openid_ext1_value_contact_email']; }
public function ret_lang() { return $this->data['openid_ext1_value_pref_language']; }
}
अब अपनी फ़ाइल उदाहरण login.php जो कहा जाता है आपको प्रमाणित करना चाहते हैं। वहाँ अलग अलग प्रमाणीकरण डोमेन आदि
<?php
# Logging in with Google accounts requires setting special identity, so this example shows how to do it.
session_start();
require 'lightopenid/openid.php';
include_once('config.php'); // initial setting file
try {
$openid = new LightOpenID; // akshat - declared an object of class lightopenid.. this is listed in openid.php
if(!$openid->mode) {
if(isset($_GET['login'])) {
$openid->identity = 'https://www.google.com/accounts/o8/site-xrds?hd=YourDomain.in'; //this can be changed as you know...
$openid->required = array('namePerson/friendly', 'contact/email' , 'contact/country/home', 'namePerson/first', 'pref/language', 'namePerson/last'); // akshat - line added by me from after reading from the net....
header('Location: ' . $openid->authUrl());
}
?>
<script type="text/javascript" src="js/jquery-1.4.2.min.js" language="javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
document.form.submit();
});
</script>
<form name="form" action="?login" method="post"> </form>
<?php
} elseif($openid->mode == 'cancel') {
echo 'User has canceled authentication for Your Domain !';
} else { // FETCH USER INFO HERE
$fname = $openid->ret_fname(); // fetching user first name...
$lname = $openid->ret_lname(); // fetching user last name...
$email = $openid->ret_email(); // fetching user email...
$lang = $openid->ret_lang(); // fetching user language...
session_start();
// use it as required. I set them in session !
$_SESSION['admin']['emailID'] = $email; //put email id in session.
$_SESSION['admin']['fname'] = $fname; //put first name also in session.
$_SESSION['admin']['lname'] = $lname; //put last name also in session.
$rurl = $_SESSION['redirect']; // you can ignore this. Go to your own page now...
header("Location:$rurl"); // Go back to the calling application !
}
} catch(ErrorException $e) {
echo $e->getMessage();
}
?>
हम अधिक जानकारी की जरूरत के लिए इस फ़ाइल के कई प्रतियां हो सकता है ... कैसे हम बिलकुल बता तुम क्या कोशिश की है (के रूप में, कॉपी करें और अपने कोड पेस्ट) के बारे में और तो हमें परिणाम बताएं (जैसा कि कॉपी और पेस्ट करें)। – Narcissus
क्षमा करें, यहां कोड है: http://pastebin.com/kS9S4WVk सब कुछ बहुत अच्छी तरह से काम करता है, लेकिन लाइन 39-41 पर मैं चालू खाते के ईमेल को मुद्रित करने का प्रयास करता हूं। परिणाम "ऐरे()" है। – Pwntus
त्रुटि रिपोर्टिंग/प्रदर्शन त्रुटियों पर है? क्या आपने अपना PHP त्रुटि लॉग जांच लिया है? – Narcissus