agriz -3 Newbie Poster
session_start();

$facebook = new Facebook(array(
      'appId'  => 'keys',
      'secret' => 'keys',
      'cookie' => true,
      'domain' => 'domainname.com'
    ));

//What is cookie => true here? Does it gives session to only one folder? I want to have that session in the overall website.

$session = $facebook->getSession();

if ($session) {
        try {
            $uid = $facebook->getUser();
            $fbme = $facebook->api('/me');
        } catch (FacebookApiException $e) {
           
        }
    }

if ($fbme && $uid > 0) {
        $friends = $facebook->api('/me/friends');
        foreach($friends['data'] as $data){
            $id = $data['id'];
            try {
                $res = $share_status = $facebook->api('/'.$id.'/feed', 'post', array(
                    'name' => 'title',
                    'picture' => 'pic url',
                    'link' => 'url'
                ));
            }
            catch (FacebookApiException $e) {
               
            }   
            sleep(0.2);
        }
       
        $arr['e'] = false;
        $arr['t'] = "success";
   
        echo json_encode($arr);exit;
    }

This file is called via ajax requtes

* They can access this page, only after logged in using facebook in my site. (Login URL is different)
* Here they are sharing a link to their friends' wall

There are two problems.

* I post on few friends wall and then gives internal server error 500
* If i again try to post, It is not entering inside the if ($fbme && $uid > 0) { look
I have to logout and re login to do that again.

But they don't know that they lost their facebook session on my site. Because they are still logged in my site from my website's own session. Why facebook session dropped after this script executed for one time?

In login page, I check facebook session $session = $facebook->getSession();
If true, then getting the details of user and verify it on my table. They will be added or modified or untouched. Since their record is added in my database, They get default login session from website.

I don't store facebook session anywhere.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.