2015-01-22 3 views
-1
<?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); 
} 

?> 

페이지 내가 페이스 북 SDK의 대학 데이터를 얻을 수

name{"school":{"id":"1234567890","name":"Universiti Tunku Abdul Rahman"},"type":"College"} 

, 난 단지 학교 이름을 원하고 $ _SESSION으로 저장의 반환에 페이스 북의 교육을 받기 내가 어떻게 그런 짓을 하겠어? 내가 $ _SESSION으로 데이터 저장소를 가져올 방법이없는 배열입니다.

+3

HEJ을 읽을 php.net의 웹 사이트를 확인합니다. 꽤 멋지 며 PHP 스크립트를 작성하기 전에 일부를 읽어야합니다. –

+0

가능한 [PHP에서 세션 변수에 배열을 저장하는 방법] 중복 (http://stackoverflow.com/questions/18499034/how-to-store-an-array-into-a-session-variable-in- PHP) –

+0

몇 년 전에 PHP의 기본 사항을 먼저 배우십시오! 수퍼 기본을 모른 채 고급 기술을 구축하려는 경우에만 큰 문제가 발생할 수 있습니다. – Sliq

답변

0

사용 json_decode는, 배열

$myArray = json_decode($data, true); 
echo $myArray[0]['id']; // Fetches the first ID 
echo $myArray[0]['name']; // Fetches the first name 
+0

작동하지 않습니다 ~~ –

+0

$ myArray = json_decode ($ college, true); echo $ myArray [0] [ 'id']; // 첫 번째 ID를 가져옵니다. echo $ myArray [0] [ 'name']; // 첫 번째 이름을 가져옵니다. –

+0

json_decode()가 반환합니다. 매개 변수 1은 string이고 배열은 다음과 같습니다. –