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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:31:43+00:00 2026-06-09T16:31:43+00:00

I’m trying to create a website that allows users to login with their Facebook

  • 0

I’m trying to create a website that allows users to login with their Facebook account. I do not need to make any requests or store any info when they are not on the website and so I do not need a database.

I am only going to accept login with Facebook and no other login types are required. I will need the typical login with Facebook button on the login page and the ability to keep them logged in across multiple pages. I would also like to add an ability to log out.

I’ve downloaded the PHP SDK and I am using the JavaScript SDK together on my pages, but I am having so much trouble.

Is it just me or does the Facebook SDK completely suck?

My first problem is that the JavaScript SDK on the login page doesn’t redirect the user to the main page after authentication. I am manually refreshing the page currently (the PHP SDK realizes that the user is logged in and sends the user to the main page).

Another issue is logout. I am using the PHP SDK’s getLogoutURL() function, and it logs the user out of Facebook, but my access token is still fully valid and PHP refuses to send the user to the login page. Why? I have no idea. Personally, I’d like that the user be logged out of my website and not Facebook.

I’m trying to make a seamless login system with Facebook, but I’m having nothing but trouble! I can’t seem to find any good documentation on Facebook Connect at all. I’m using their examples and problems like this are happening. Maybe they just can’t make a good SDK. I’d like to use the PHP SDK and the JavaScript SDK to make a very nice user experience, but it just doesn’t seem possible.

login.php’s PHP code

require_once("../fb-sdk/src/facebook.php");

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

$User = $Facebook->getUser();

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

if ($User)
{
  header("Location: index.php");
}

?>

login.php’s JavaScript code

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'xx', // App ID
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });
  };
  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>
<div class="fb-login-button">Login with Facebook</div>

index.php’s PHP code

require_once("../fb-sdk/src/facebook.php");

$Facebook = new Facebook(array(
  "appId"  => "xx",
  "secret" => "xx",
));

$User = $Facebook->getUser();

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

if (!$User)
{
  header("Location: login.php");
}

?>
  • 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-09T16:31:44+00:00Added an answer on June 9, 2026 at 4:31 pm

    You have to subscribe for login event to get callback and then you can refresh your page. Also for logout you should used your own SESSION of site for login logout beside facebook login, so lets say if you get userid from facebook by calling this function (means user is login with facebook)

    $User = $Facebook->getUser();
    

    Then set something like this in your session, and use this variable to check login status of user with your web.

    $_SESSION['LOGIN'] = 1;
    

    and when you logout you can simply unset this variable or destroy session.

    Here are the links of tutorial which gives you more detail on facebook SDK in PHP / JS

    http://thinkdiff.net/facebook/graph-api-javascript-base-facebook-connect-tutorial/

    http://thinkdiff.net/facebook/php-sdk-3-0-graph-api-base-facebook-connect-tutorial/

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

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.