Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6666647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:51:02+00:00 2026-05-26T02:51:02+00:00

For that purpose I used two methods but neither is working. For Method 1

  • 0

For that purpose I used two methods but neither is working.
For Method 1 I downloaded three files:

  1. base_facebook.php
  2. facebook.php
  3. fb_ca_chain_bundle.crt

Method 1

   include ('facebook.php');
   $facebook = new facebook('API','SECRET');
   $fbid = $facebook->getUser(); 

   echo $fbid; // when i echo this it always show 0; even the followers are logedin or logedout
   echo "<div class='' id=\"user-icon\"><img src=\"'https://graph.facebook.com/{'.$fbid.'}/picture{?type=small}'\"  /></div>";

Method 2

class sfFacebookPhoto{
   private $useragent = 'Loximi sfFacebookPhoto PHP5 (curl)';
   private $curl = null;
   private $response_meta_info = array();
   private $header = array(
      "Accept-Encoding: gzip,deflate",
      "Accept-Charset: utf-8;q=0.7,*;q=0.7",
      "Connection: close"
 );
 public function __construct() {
    $this->curl = curl_init();
    register_shutdown_function(array($this, 'shutdown'));
 }
/**
 * Get the real url for picture to use after
 */
public function getRealUrl($photoLink) {
    curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->header);
    curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, false);
    curl_setopt($this->curl, CURLOPT_HEADER, false);
    curl_setopt($this->curl, CURLOPT_USERAGENT, $this->useragent);
    curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($this->curl, CURLOPT_TIMEOUT, 15);
    curl_setopt($this->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($this->curl, CURLOPT_URL, $photoLink);
    //        curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
    //this assumes your code is into a class method, and uses $this->readHeader as the callback //function
    curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, array(&$this, 'readHeader'));
    $response = curl_exec($this->curl);
    if (!curl_errno($this->curl)) {
        $info = curl_getinfo($this->curl);
        var_dump($info);
        if ($info["http_code"] == 302) {
            $headers = $this->getHeaders();
            if (isset($headers['fileUrl'])) {
                return $headers['fileUrl'];
            }
         }
     }
     return false;
 }
/**
 * Download facebook user photo
 * 
 */
  public function download($fileName) {
      curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->header);
      curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($this->curl, CURLOPT_HEADER, false);
      curl_setopt($this->curl, CURLOPT_USERAGENT, $this->useragent);
      curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 10);
      curl_setopt($this->curl, CURLOPT_TIMEOUT, 15);
      curl_setopt($this->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
      curl_setopt($this->curl, CURLOPT_URL, $fileName);
      curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
      $response = curl_exec($this->curl);
      $return = false;
      if (!curl_errno($this->curl)) {
            $parts = explode('.', $fileName);
            $ext = array_pop($parts);
            $return = sfConfig::get('sf_upload_dir') . '/tmp/' . uniqid('fbphoto') . '.' . $ext;
            file_put_contents($return, $response);
       }
       return $return;
     }
    /**
    * CURL callback function for reading and processing headers
    * Override this for your needs
    *
    * @param object $ch
    * @param string $header
    * @return integer
    */
    private function readHeader($ch, $header) {
     //extracting example data: filename from header field Content-Disposition
      $filename = $this->extractCustomHeader('Location: ', '\n', $header);
      if ($filename) {
          $this->response_meta_info['fileUrl'] = trim($filename);
      }
      return strlen($header);        
    }
    private function extractCustomHeader($start, $end, $header) {
       $pattern = '/' . $start . '(.*?)' . $end . '/';
       if (preg_match($pattern, $header, $result)) {
           return $result[1];
       } else {
          return false;
       }
   }
   public function getHeaders() {
       return $this->response_meta_info;
   }
   /**
   * Cleanup resources
   */
   public function shutdown() {
       if ($this->curl) {
          curl_close($this->curl);
       }
   }
}

I saved the above class as curl.php.

   require_once 'curl.php';
   $photo="https://graph.facebook.com/me/picture?access_token=".$session['access_token'];
   $sample = new sfFacebookPhoto;
   $thephotoURL=$sample->getRealUrl($photo);
   echo $thephotoURL;                        
   // but here echo is not showing anything no-error, no-exception, no-output.
   echo "<div id=\"user-icon\"><img src=\"$thephotoURL\"  /></div>";

As you can see I want to display images of Facebook users in my comments.
As in WordPress or Joomla when a Facebook user comments, their Facebook profile image shows with comments. My website is not using WordPress or Joomla.
It’s PHP based, I created it myself.
I used Avatars code which is working fine if any WordPress user comments on my website. His/her image shows but not Facebook user’s.

I am using this code for WordPress Avatars which is working fine:

$hash = md5( strtolower( trim( $row['email'] ) ) );
$default_usr = urlencode( 'http://www.kingofdevelopers.com/images/user-icon.png'); 
echo "<div class='default-user' id=\"user-icon\"><img src=\"http://www.gravatar.com/avatar /$hash.'.jpg?s=45&d=$default_usr'\"  /></div>";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:51:02+00:00Added an answer on May 26, 2026 at 2:51 am

    Facebook already has an easier way to do this.

    http://developers.facebook.com/blog/post/198/

    http://www.ruhanirabin.com/easy-steps-to-facebook-connect-comment-box-how-to/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any fast algorithm that allows to compare two files (for verification purpose)
I have historically used a monolithic approach to PHP coding. That is, I write
I have a Generic Class Factory class that has two methods one utilizes the
I keep hearing that div tags should be used for layout purposes and not
I have a huge table that is mainly used for backup and administrative purposes.
I need to un-read characters from an InputStreamReader . For that purpose I wanted
I am aware that the purpose of volatile variables in Java is that writes
To have a general-purpose documentation system that can extract inline documentation of multiple languages,
It is my opinion that every language was created for a specific purpose. What
Let's say that I'm considering designing a WCF service whose primary purpose is to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.