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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:34:37+00:00 2026-05-30T12:34:37+00:00

Going over the Facebook API and I’m a bit confused on the right approach.

  • 0

Going over the Facebook API and I’m a bit confused on the right approach. I want users to skip registration, or auto-register them if they sign in with Facebook. So if they sign into Facebook I collect their id, email and create a record in my user table.

If an id exists already in the user table they skip the auto-registration and go directly to the members page. This is my code so far (taken from Facebook’s PHP SDK example). When I run the signup script the page shows up as blank, I do not get redirected.

EDIT: seems to be failing right after the require, if I use the following code ‘test’ never gets printed.

EDIT: I’m using Codeigniter and this script is part of a controller, would that cause a problem with the require?

require 'http://localhost/facebook-php-sdk-6c82b3f/src/facebook.php';
echo "test";

–

public function signup()
    {   
        require 'http://localhost/facebook-php-sdk-6c82b3f/src/facebook.php';

        // Create our Application instance (replace this with your appId and secret).
        $facebook = new Facebook(array(
          'appId'  => 'xxxxxxxxxxxxxxx',
          'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
        ));

        // Get User ID
        $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;
            }
        }

        // Login or logout url will be needed depending on current user state.
        if ($user)
        {
            $logoutUrl = $facebook->getLogoutUrl();
        }
        else
        {
            $loginUrl = $facebook->getLoginUrl(array('scope' => 'email'));
            redirect($loginUrl);
        }

        print_r($user_profile);


        $this->load->model("user_model");
        $privileges = 1;
        $loginLocation = ip2long($_SERVER['REMOTE_ADDR']);
        $active = 1;
        $this->user_model->add_user($user_profile->id, $user_profile->name, $user_profile->email, $loginLocation, $privileges, $active);

    }
  • 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-30T12:34:38+00:00Added an answer on May 30, 2026 at 12:34 pm

    I suggest you read the framework documentation. Adding a library to CodeIgniter is not a hard task. And Facebook library is no exception.

    Here’s a quick integration I’ve just come up with:

    1.create a config file:application/config/facebook.php

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    $config['appId'] = 'app_id';
    $config['secret'] = 'app_secret';
    

    2.place the sdk files in the libraries folder application/libraries/ and rename the facebook.php file to Facebook.php and replace the php tag with this:

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    

    3.in your controller load the config file and then load the Facebook library:

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Welcome extends CI_Controller {
    
        public function __construct()
        {
            parent::__construct();
            // Your own constructor code
            $CI = & get_instance();
            $CI->config->load("facebook",TRUE);
            $config = $CI->config->item('facebook');
            $this->load->library('facebook', $config);
        }
    
        public function index()
        {
            $user = $this->facebook->getUser();
            if($user) {
                try {
                    $user_info = $this->facebook->api('/me');
                    echo '<pre>'.htmlspecialchars(print_r($user_info, true)).'</pre>';
                } catch(FacebookApiException $e) {
                    echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
                    $user = null;
                }
            } else {
                echo "<a href=\"{$this->facebook->getLoginUrl()}\">Login using Facebook</a>";
            }
        }
    }
    

    Now in the constructor method, you have just initialized the Facebook library (sdk) and it can be accessed by using: $this->facebook.

    Notes:

    • You can always use an existing library, just google it
    • A common practice is to extend the core Controller class and add the Facebook library initialization there.
    • Or create another library, extend the Facebook library, load the config file there and then autoload this new library.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently going over my user registration code. The part I'm focusing on right
I am going over/studying the facebook code that was leaked in 2007, I notice
I'm going for a Facebook-esque slide-over UITableView. I've accomplished that, animation and drop shadow
Been going over my predecessor's code and see usage of the request scope frequently.
I've been going over and over this in my head, and I can't seem
So we start Scrum today and start going over story points estimates. The first
I've moved to a new project team and while going over the codebase, found
I'm going back over an old project where I added preprocessor functionality to Essence'
When I iterate over the values or keys are they going to correlate? Will
When creating an index over a column that is going to be UNIQUE (but

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.