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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:54:38+00:00 2026-06-10T21:54:38+00:00

I am Trying to set up my website so that when you go onto

  • 0

I am Trying to set up my website so that when you go onto the login page it checks if a cookie is set and if it is then the login should be automatic – i.e. when this page loads it redirects to “Facebook.ashx” which creates a cookie to remember access token.

However if the cookie is not set then the user has to click on the Login with Facebook button to continue login which then continues to redirect to “Facebook.ashx” as before.

This is my code – at the moment it always logs in once the user has accepted the app and continues to “Facebook.ashx”

<div id="fb-root"></div>  
<script type="text/javascript">
    window.fbAsyncInit = function () {
        FB.init({
            appId: 'My_App_ID', // App ID
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true  // parse XFBML
        });

        // Additional initialization code here

        FB.Event.subscribe('auth.authResponseChange', function (response) {
            if (response.status === 'connected') {
                // the user is logged in and has authenticated your
                // app, and response.authResponse supplies
                // the user's ID, a valid access token, a signed
                // request, and the time the access token 
                // and signed request each expire
                var uid = response.authResponse.userID;
                var accessToken = response.authResponse.accessToken;

                // TODO: Handle the access token
                // Do a post to the server to finish the logon
                // This is a form post since we don't want to use AJAX
                var form = document.createElement("form");
                var redirect = "FacebookLogin.ashx?redirect=" + document.getElementById('redirect').innerHTML;
                form.setAttribute("method", 'post');
                form.setAttribute("action", redirect);

                var field = document.createElement("input");
                field.setAttribute("type", "hidden");
                field.setAttribute("name", 'accessToken');
                field.setAttribute("value", accessToken);
                form.appendChild(field);

                document.body.appendChild(form);
                form.submit();

            } else if (response.status === 'not_authorized') {
                // the user is logged in to Facebook, 
                // but has not authenticated your app
            } else {
                // the user isn't logged in to Facebook.
            }
        });
    };

  // 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" scope="email, publish_stream">Login with Facebook</div>

Thanks For any help 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-10T21:54:40+00:00Added an answer on June 10, 2026 at 9:54 pm

    I worked it out – simple fix

    If you change the status to false rather than true then it waits for the user to click login and to check if cookie exists just a simple if statement to change the status to true or false like so:

    if (document.cookie.indexOf("fb_token") > 0) //user has already logged in with facebook - process should be automatic
            var fb_status = true;
        else
            var fb_status = false;
        window.fbAsyncInit = function () {
            FB.init({
                appId: 'My App ID', // App ID
                status: fb_status, // check login status
                cookie: true, // enable cookies to allow the server to access the session
                xfbml: true  // parse XFBML
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set up page anchors on a website that uses mod_rewrite (Apache2
I'm currently trying to set up a website that uses both windows authentication and
I'm trying to set up Git for staging my website so that I can
I'm trying to set up some tests for a website that has a forum.
I am trying to set up a mono asp.net 4.0 test website that uses
I am trying to set up smart card authentication for a website that I
I'm trying to set up a website using HTML and JavaScript that displays sections
I'm trying to set up a website that runs in a single WebGL element.
This is the scenario: There's an intranet website that stores a set of macros
I have a website that makes an ajax call and then loads a gif

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.