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 6330455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:52:24+00:00 2026-05-24T17:52:24+00:00

I am new to PHP, and have had a very difficult time understanding the

  • 0

I am new to PHP, and have had a very difficult time understanding the facebook login system.

I have downloaded the three src/ files from github (https://github.com/facebook/php-sdk/). I tried using the example.php file to get me started. However, I am not sure what to do with it.

For those who are unfamiliar with the file, here is a copy of example.php, with some of the styling removed:

require '../src/facebook.php';
$facebook = new Facebook(array(
  'appId'  => '...',
  'secret' => '...',
));
$user = $facebook->getUser();
if ($user) {
  try {
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}
$naitik = $facebook->api('/naitik');
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <body>
    <?php if ($user): ?>
      <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
      <div>
        Login using OAuth 2.0 handled by the PHP SDK:
        <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
      </div>
    <?php endif ?>

    <h3>PHP Session</h3>
    <pre><?php print_r($_SESSION); ?></pre>

    <?php if ($user): ?>
      <h3>You</h3>
      <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">

      <h3>Your User Object (/me)</h3>
      <pre><?php print_r($user_profile); ?></pre>
    <?php else: ?>
      <strong><em>You are not Connected.</em></strong>
    <?php endif ?>

    <h3>Public profile of Naitik</h3>
    <img src="https://graph.facebook.com/naitik/picture">
    <?php echo $naitik['name']; ?>
  </body>
</html>

Here are the questions I have in regard to it:

1)What about cookies?–I want the user to be able to be logged into my website after re-opening his/her browser.

2)What is the bare minimum I need to get out of this example.php file to validate/register a user, begin a session, store the session in a cookie, get the user’s fb user id, fb name, fb picture, and list of fb friends?

3)In the src/ files, there is one ‘file fb_ca_chain_bundle.crt,’ and I am completely unfamiliar with what such a file, and I am not sure if it is even necessary. What is its purpose?

4)The line $naitik = $facebook->api('/naitik'); is “naitik” the username of this person–so if I type facebook.com/naitik it will show his public profile? is replacing “/naitik” with “/me” what will get the public profile of the person logged into facebook?

5)How do I get the access token, and how do I use it in my code?

6)When I create a session for the user, and a cookie so that the user is logged in after reopening the browser, what should I exactly be storing in my sessions and cookies?

I know this is many questions, but I have looked through many tutorials online, and none of them have done a good job explaining this, mostly because they just link back to the Github PHP-SDK files. Plus, most of them explain a previous version of PHP-SDK.
Any help is appreciated, with any of the questions.

  • 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-24T17:52:25+00:00Added an answer on May 24, 2026 at 5:52 pm

    To answer your questions

    1)What about cookies?

    You just add a parameter to the Facebook initialization.
    Change it to the following

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

    2)What is the bare minimum I need to get out of this example.php file to ….

    Not everything you want is in this example. The top half of the code shows you how to connect and validate a user. The second half just dumps out their basic details and naitik’s details. For the rest you need to look further.

    3)In the src/ files, there is one ‘file fb_ca_chain_bundle.crt,’

    The purpose of this file is to offer a workaround for CURL error 60. Read this:

    http://www.takwing.idv.hk/blog/2011/php-sdk-demystified-%E2%80%93-how-curl-error-60-is-handled/

    4)The line $naitik = $facebook->api(‘/naitik’); is “naitik” the username of this person–so if I type facebook.com/naitik it will show his public profile? is replacing “/naitik” with “/me” what will get the public profile of the person logged into facebook?

    Exactly right

    5)How do I get the access token, and how do I use it in my code?

    $facebook->getAccessToken();

    You add it some of the method calls, but it is not necessary for everything.

    6)When I create a session for the user, and a cookie so that the user is logged in after reopening the browser, what should I exactly be storing in my sessions and cookies?

    The Facebook SDk is going to take care of that. You will just need to store whatever extra information about the user your App requires.

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

Sidebar

Related Questions

I'm very new to PHP and I have a small task of displaying a
Basically i am quite new to PHP and recently i have had heard quite
I'm new to PHP and have installed on Linux to boot (also a newbie).
I'm fairly new to PHP and have built a medium sized website using standard
I'm quite new to php and have been reading Larry Ullman book to develop
Hi I am quite new to php but i have been following some tutorials
I'm new to DOM parsing in PHP: I have a HTML file that I'm
I am new to php. I want to have a form such as this:
I'm new to PHP and trying to get my head around security. I have
I am pretty new to php, but I am learning! I have a simple

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.