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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:43:49+00:00 2026-06-03T04:43:49+00:00

i have a facebook login on my website and when you click it it

  • 0

i have a facebook login on my website and when you click it it launches a pop up where the user signs into Facebook and if they haven’t authorised my site it does that. I know you can request data using Facebook scope function but how do I take this data and store it in a database so I can save their email address etc. I have a register function using Facebook which saves the data into my database but I was wondering if I could streamline login and authorisation this way? if so how would I do it? thanks in advance

  • 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-03T04:43:51+00:00Added an answer on June 3, 2026 at 4:43 am

    You can work with sessions.

    First download Facebook PHP SDK here: https://github.com/facebook/php-sdk

    Put facebook.php and base_facebook.php in the folder “facebook”

    Put dbconfig.php in folder “config”. Source:

    <?php
    
    define('DB_SERVER', 'localhost');
    define('DB_USERNAME', 'username');
    define('DB_PASSWORD', 'password');
    define('DB_DATABASE', 'db_name');
    $connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
    $database = mysql_select_db(DB_DATABASE) or die(mysql_error());
    
    ?>
    

    functions.php in the folder “config”. Source:

    <?php
    
    require 'dbconfig.php';
    
    class User {
        function checkUser($uid, $username, $email) 
        {
            $query = mysql_query("SELECT * FROM `users` WHERE oauth_uid = '$uid'") or die(mysql_error());
            $result = mysql_fetch_array($query);
            if (!empty($result)) {
                # User is already present
            } else {
                #user not present. Insert a new Record
                $query = mysql_query("INSERT INTO `users` (id, oauth_uid, username, email) VALUES ('', $uid, '$username', '$email')") or die(mysql_error());
                $query = mysql_query("SELECT * FROM `users` WHERE oauth_uid = '$uid'");
                $result = mysql_fetch_array($query);
                return $result;
            }
            return $result;
        }
    }
    
    ?>
    

    fbconfig.php in folder “config”. Source:

    <?php
    
    define('APP_ID', 'xxxxxxxxxxxxxx');
    define('APP_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
    
    ?>
    

    logout.php source:

    <?php
    
    if (array_key_exists("logout", $_GET)) {
        session_start();
        unset($_SESSION['id']);
        unset($_SESSION['username']);
        session_destroy();
        header("location: home.php"); // or anywhere where you want them to redirect them to
    }
    ?>
    

    Example usage login.php. Source:

    <?php
    
    require 'facebook/facebook.php';
    require 'config/fbconfig.php';
    require 'config/functions.php';
    
    $facebook = new Facebook(array(
                'appId' => APP_ID,
                'secret' => APP_SECRET,
                ));
    
    $user = $facebook->getUser();
    
    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;
      }
        if (!empty($user_profile )) {
            # User info ok? Let's print it (Here we will be adding the login and registering routines)
    
            $username = $user_profile['name'];
            $uid = $user_profile['id'];
            $email = $user_profile['email'];
            $user = new User();
            $userdata = $user->checkUser($uid, $username, $email);
            if(!empty($userdata)){
                session_start();
                $_SESSION['id'] = $userdata['id'];
                $_SESSION['oauth_id'] = $uid;
                $_SESSION['username'] = $userdata['username'];
                $_SESSION['email'] = $userdata['email'];
                header("Location: home.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
        $login_url = $facebook->getLoginUrl(array( 'scope' => 'email')); // you can add more scopes
        header("Location: " . $login_url);
    }
    ?>
    

    Example usage home.php. Source:

    <?php
    
    //Always place this code at the top of the Page
    session_start();
    if (!isset($_SESSION['id'])) {
        // Not logged in? Redirect to main page
        header("location: index.php");
    }
    
    echo '<h1>Welcome</h1>';
    echo 'id : ' . $_SESSION['id'];
    echo '<br /><img src="https://graph.facebook.com/' . $_SESSION['oauth_id'] . '/picture?type=large">';
    echo '<br />Name : ' . $_SESSION['username'] . ' (' . $_SESSION['oauth_id'] . ')' ;
    echo '<br />Email : ' . $_SESSION['email'];
    echo '<br />You are login with : ' . $_SESSION['oauth_provider'];
    echo '<br />Logout from <a href="logout.php?logout">' . $_SESSION['oauth_provider'] . '</a>';
    
    ?>
    

    Edit fbconfig.php and dbconfig.php with your own details. This is a copy/paste from my own files, but they will give you an idea how you can authenticate and login users through facebook and create users with the info facebook provides.

    Good luck!

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

Sidebar

Related Questions

I am trying to make a Facebook login in my website, I have faced
I have website where users can login with their Facebook account. I am using
I have facebook login setup in my android app. When the user clicks login
I have a Facebook connect site and am having issues with the Facebook login
I have a website where I want to implement the facebook-login facility.. I went
We have a website that uses Facebook for login. We have an invite page
I have OmniAuthable Facebook login on my website. Users login with: link_to user_omniauth_authorize_path(:facebook) It
I am planning to integrate a Facebook Login button into my website. Right now
I have been experimenting using a Facebook login button on my website. The login
I have an application where i need to login to a website through facebook,

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.