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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:40:00+00:00 2026-06-16T09:40:00+00:00

I want to let user login via facebook. I’m using this code: <?php require

  • 0

I want to let user login via facebook. I’m using this code:

  <?php

    require 'include/facebook.php';
    require 'include/fbconfig.php';
    require 'include/user.php';

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

    $session = $facebook->getSession();

    if (!empty($session)) {
        # Active session, let's try getting the user id (getUser()) and user info (api->('/me'))
        try {
            $uid = $facebook->getUser();
            $user = $facebook->api('/me');
        } catch (Exception $e) {

        }

        if (!empty($user)) {
            # User info ok? Let's print it (Here we will be adding the login and registering routines)
            echo '<pre>';
            print_r($user);
            echo '</pre><br/>';
            $username = $user['name'];
            $user = new User();
// check user method insert login information to my database and return the result
            $userdata = $user->checkUser($uid, 'facebook', $username);
            if(!empty($userdata)){
                session_start();
                $_SESSION['id'] = $userdata['id'];
                $_SESSION['oauth_id'] = $uid;
                $_SESSION['username'] = $userdata['username'];
                $_SESSION['oauth_provider'] = $userdata['oauth_provider'];
                header("Location: test.php");
            }
        } else {
            # For testing purposes, if there was an error, let's kill the script
            die("There was an error.");
        }
    } else {
        # There's no active session, let's generate one
        $params = array(
         'scope' => 'email'
      );
        $login_url = $facebook->getLoginUrl($params);
        header("Location: " . $login_url);
    }
    ?>

The problem when I run this page, it redirects me to the facebook home page(to my account ).

Please, any ideas ??
Your post does not have much context to explain the code sections; please explain your scenario more clearly.

  • 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-06-16T09:40:01+00:00Added an answer on June 16, 2026 at 9:40 am

    Are you using the newest PHP SDK? Get the latest SDK from here, and then try again..

    [EDITED]

    Replace all references to getSession() with getUser()

    Example:

    $session = $facebook->getSession();
    

    it should say:

    $session = $facebook->getUser();
    

    ref: Upgrade to PHP SDK v3.0.0

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

Sidebar

Related Questions

I am developing iPhone app that let user login using their facebook account using
This is what I want : Let the user enter as many numbers as
I'm using jquery ui draggable, I do not want to let the user drag
I'm using DataTables . I want to let the user select multiple rows and
First time here. Let's hope this works! I'm new to PHP and trying to
I want to let people to log in with Facebook login. but, I wonder
i have used oauth mechanism to let the user login via twitter in my
I have a Multiline Textbox . I donot want to let user type HTML
So I have a file for constants. I want to let user define them
I want to let the user download the current content of a textarea into

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.