<?php
session_start();
require 'config.php';
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => $appID,
'secret' => $appSecret,
));
$user = $facebook->getUser();
if($user){
try{
$user_profile = $facebook->api('/me');
$params = array('next' => 'website' );
$logout =$facebook->getLogoutUrl($params);
$_SESSION['User']=$user_profile;
$college = null;
foreach ($user_profile['education'] as $education) {
if ($education['type'] == "College") { //store the name data
$college = $education;
break;
}
}
if(empty($college)) {
echo "College information was not found!";
} else {
// var_dump($college);
echo "name" . json_encode($college);
}
?>
返回页面
name{"school":{"id":"1234567890","name":"Universiti Tunku Abdul Rahman"},"type":"College"}
我从Facebook获得大学数据sdk,我只想要学校名称和商店进入$ _SESSION我将如何做到这一点?是一个数组我不知道如何将数据存储到$ _SESSION。
答案 0 :(得分:0)
使用json_decode读取数组
$myArray = json_decode($data, true);
echo $myArray[0]['id']; // Fetches the first ID
echo $myArray[0]['name']; // Fetches the first name