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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:40:48+00:00 2026-06-14T02:40:48+00:00

I am using the following code to store my facebook app users details in

  • 0

I am using the following code to store my facebook app users details in mysql to allow them to see exclusive content on my website.

My question is simple, How can I store the access token of the user in my Mysql table to use it later to post to wall later

<?php 
session_start(); 
if(isset($_POST["connect"]) && $_POST["connect"]==1)
 {      
include_once("config.php"); //Include configuration file.

//Call Facebook API
if (!class_exists('FacebookApiException')) {
require_once('inc/facebook.php' );
}
    $facebook = new Facebook(array(
    'appId' => $appId,
    'secret' => $appSecret,
));

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





// redirect user to facebook login page if empty data or fresh login requires
if (!$fbuser){
    $loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$return_url, false));
    header('Location: '.$loginUrl);
}

//user details
$fullname = $me['first_name'].' '.$me['last_name'];
$email = $me['email'];
$username = $me['username'];
$gender = $me['gender'];
$locale = $me['locale'];
$token = $me['token'];

/* connect to mysql */
$connecDB = mysql_connect($hostname, $db_username, $db_password)or die("Unable to connect to MySQL");   
mysql_select_db($db_name,$connecDB);

//Check user id in our database
$result = mysql_query("SELECT COUNT(id) FROM usertable WHERE fbid=$uid");   
$UserCount = mysql_fetch_array($result); 

if($UserCount[0])
{   
    //User exist, Show welcome back message
echo 'Ajax Response :<br /><strong>Welcome back '. $me['first_name'] . ' '. $me['last_name'].'!</strong> AT : '.$token.' ( Facebook ID : '.$uid.') [<a href="'.$return_url.'?logout=1">Log Ouuuuuuuuuuuuuut</a>]';
echo '<iframe style="width:1309px; height:526px" src="post2.php"></iframe>';

    //User is now connected, log him in
    login_user(true,$me['first_name'].' '.$me['last_name']);
}
else
{
    //User is new, Show connected message and store info in our Database
    // Insert user into Database.
    @mysql_query("INSERT INTO usertable (fbid, fullname, email, username, gender, token, locale) VALUES ($uid, '$fullname','$email','$username','$gender','$token','$locale')");

    //User is now connected, log him in
    login_user(true,$me['first_name'].' '.$me['last_name']);
}

mysql_close($connecDB);
   }

  function login_user($loggedin,$user_name)
  {
/*
function stores some session variables to imitate user login. 
We will use these session variables to keep user logged in, until s/he clicks log-out link.
If you are using some authentication library, login user with it instead.
*/
$_SESSION['logged_in']=$loggedin;
$_SESSION['user_name']=$user_name;
 }

 ?>
  • 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-14T02:40:49+00:00Added an answer on June 14, 2026 at 2:40 am

    I don’t understand. You are already saving the token.

    What you need to, is to verify in the authenticated-only page if the user is logged in, if so, you will return the token for his $_SESSION[‘user_id’] (for ex.), and create the interactions within Facebook API with that token, using for example:

    $token = $_SESSION['token'];
    $facebook->setAccessToken($token);
    

    I hope It did help you.

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

Sidebar

Related Questions

I create random numbers using the following code and store them in an array.
I am using the following code: if (store.getItem('TopicID') != 00) TopidID is always 4
I am using the following code to store values in aspx session. Code: $(div.menu_body
I am using the following code to store data in shared pref. However when
I am using the following tcl code to store a file from my deskstop
Users have been able to log into my website using their Facebook account, but
I'm using the Facebook send plugin (the HTML5 code) with the following code: <div
I use the following code to store a password into mysql if (!$errors) {
I am using following code: var genres1 = new Ext.data.Store({ reader: new Ext.data.JsonReader({ fields:
I want to find certificate from my store but using following code i could

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.