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

  • Home
  • SEARCH
  • 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 7508153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:37:48+00:00 2026-05-29T22:37:48+00:00

I am using Facebook PHP SDK to authenticate the user. After generating the LoginUrl

  • 0

I am using Facebook PHP SDK to authenticate the user. After generating the LoginUrl using the PHP SDK, the user clicking on that LoginUrl gets redirected to the Facebook page asking for permission. After clicking on the Go to App link, the user gets redirected back to my website http://www.mydomain.com/login/facebook_connect.

Problem: After being ‘authenticated’ by Facebook, the PHP script at http://www.mydomain.com/login/facebook_connect is unable to determine that the user has logged in via Facebook. At this point, $user = $facebook->getUser(); is 0.

Did I do something wrong? Thanks!

PHP Code for page that generates LoginUrl

require 'libs/fb-php-sdk/facebook.php';

// Create our Application instance
$facebook = new Facebook(array(
  'appId'  => '123',
  'secret' => '123'
));

// Get User ID
$user = $facebook->getUser();

// Get Login URL
$loginUrl = $facebook->getLoginUrl(array(
    "scope" => "email,user_education_history,user_work_history",
    "redirect_uri" => "http://www.mydomain.com/login/facebook_connect/"
));

$data['fb_login_url'] = $loginUrl;

$this->load->view('splash', $data);

PHP Code for page user is redirected to after Facebook authentication

*http://www.mydomain.com/login/facebook_connect/*

require 'libs/fb-php-sdk/facebook.php';

    $facebook = new Facebook(array(
        'appId'  => '123',
        'secret' => '123',
    ));

    // See if there is a user from a cookie
    $user = $facebook->getUser();

    // We may or may not have this data based on whether the user is logged in.
    //
    // If we have a $user id here, it means we know the user is logged into
    // Facebook, but we don't know if the access token is valid. An access
    // token is invalid if the user logged out of Facebook.

    if ($user) {
      try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
      } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
      }
    }

    print_r($user_profile);
    echo $user;
  • 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-29T22:37:49+00:00Added an answer on May 29, 2026 at 10:37 pm

    $facebook->getUser() uses a cookie to get the user. If you use CodeIgniter, or another library that “eats” cookies that PHP assigns automatically, you need to create a proxy page outside CI, that would pick up the cookie the redirect back into CI.

    In other words, take to code you currently have in

    http://www.mydomain.com/login/facebook_connect/
    

    and create a copy in a regular PHP file:

    http://www.mydomain.com/facebook_pickup.php
    

    do not echo anything from the script (remove print_r), just redirect to

    http://www.mydomain.com/login/facebook_connect/
    

    and it would magically start working.

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

Sidebar

Related Questions

Using the Facebook Graph API and the PHP SDK, I know that I can
so I'm using the Facebook PHP SDK for authenticating my user.... and I'm trying
So I am using the facebook-php-sdk and I have created a page tab On
I'm using facebook php sdk to get friend list of an user. But I'm
I'm trying to wrtie a facebook application that generates random quotes using php. However,
I'm working on a website that will be using Facebook Connect to authenticate users.
I am using the PHP library for the Graph API ( http://github.com/facebook/php-sdk ) but
Background: Using Facebook PHP SDK v 2.1.2 cookieSupport = true App on Facebook has
My time zone is Europe/Rome . I'm using Facebook PHP SDK and insights part
I'm using the facebook php sdk on two of my sites ( here and

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.