嘿伙计我在我的网站上使用开放式身份验证,在验证后我从openid提供商那里得到一个网址,即雅虎和谷歌
http://www.mysite.com/openid-login.php?
openid.identity=https://me.yahoo.com/a/1234567&
openid.ax.value.nickname=john&
openid.ax.value.email=john@yahoo.co.in&
http://www.mysite.com/openid-login.php?
openid.identity=https://www.google.com/accounts/o8/1234567&
openid.ext1.value.email=kevin@gmail.com&
openid.ext1.value.country=IN
为了清晰起见,我已经修剪了一些网址。我想为两者创建一个单独的函数,可以设置数组中的电子邮件(如果存在),昵称(如果退出),标识(openid ina)并返回值。例如
function userdetails(array_get){
......
......
return $userdetails;
}
$userdetails =userdetails($_GET);
$ userdetails ['nickname']会给我一个昵称,如果存在,同样适用于电子邮件和身份。感谢
答案 0 :(得分:1)
我没有创建这个功能,也没有为此付出代价。这是从Simple OpenID库中提取和修改的。如果有人有链接,请在评论中发布,因为我无权访问原始来源。
/**
* Method to filter through $_GET array for requested user information.
* Will return an array of trimmed userinfo.
*/
public function filterUserInfo($arr_get) {
$valid_ax_types = array('nickname' => 1, 'email' => 1, 'fullname' => 1, 'dob' => 1, 'gender' => 1, 'postcode' => 1, 'country' => 1, 'language' => 1, 'timezone' => 1, 'firstname' => 1, 'lastname' => 1);
$userinfo = array();
foreach ($arr_get as $key => $value) {
// trim the key
$trimmed_key = substr($key, strrpos($key, "_") + 1);
// check for valid openid_ext1 values
if (stristr($key, 'openid_ext1_value') && isset($value[1])) {
$userinfo[$trimmed_key] = $value;
}
// check for valid openid_ax values
if (stristr($key, 'openid_ax_value') && isset($value[1])) {
$userinfo[$trimmed_key] = $value;
}
// check for valid sreg_ values
else if (stristr($key, 'sreg_') && array_key_exists($trimmed_key, $arr_ax_types)) {
$userinfo[$trimmed_key] = $value;
}
}
return $userinfo;
}
答案 1 :(得分:0)
我认为“获取网址”实际上是指网址。接受我下面的答案。 :)强>
function userdetails( $url, $keep = array( 'email', 'nickname', 'identity' ) ) {
$array = parse_str( parse_url( $url, PHP_URL_QUERY ) );
$return = array();
foreach ( $keep as $key ) {
if ( isset( $array[ $key ] ) ) {
$return[ $key ] = $array[$key];
}
}
return $return;
}