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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:17:41+00:00 2026-06-06T05:17:41+00:00

I have a (currently very simple) website that is utilising Facebook’s Website with Facebook

  • 0

I have a (currently very simple) website that is utilising Facebook’s “Website with Facebook Login” app setting. My problem seems simple on the face of it, but I’m unable to work it out, could someone shed any light?

My website homepage is (say) https://www.mysite.net/
– when I log in from here using the code below, it works.

if(!$this->facebook->getUser())
    {
        //NOT LOGGED IN 
       $params = array(
          'scope' => 'email, publish_stream, user_photos, status_update',
          'redirect_uri' => current_url(),
        );  
        $auth_url = $this->facebook->getLoginUrl($params);  
        $auth_text = "Log In";
    } 
    else 
    {
        //LOGGED IN         
        $fbid = $this->facebook->getUser();
        $fbid = $fbid;
        $auth_url = "https://www.facebook.com/logout.php?confirm=1&next=".urlencode(base_url().'logout/')."&access_token=".$this->facebook->getAccessToken();
        $auth_text = "Log Out";
    }

<a href="<?=$auth_url;?>" class="btn btn-primary"><i class="icon-user"></i> <?=$auth_text;?></a>

.. that works fine.

However, when I use the same code (and the user needs to log in) from say https://www.mysite.net/second_page/, and I use the exact above code on the second page also, the login script redirects to the Facebook Auth Dialog (great), and redirects to the redirect_uri(also great), but the user is NOT logged in to the page – ie, it gives the “Log In” dialog rather than the expected “Log Out” dialog.

Am I doing something wrong here? I would expect the facebook login dialog to work from any page off my app-specified site root. I don’t want to need to redirect my users to the home page for every login, they need to be able to log in from any page of the site.

Thoughts?

Regards,
Paul G

  • 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-06T05:17:43+00:00Added an answer on June 6, 2026 at 5:17 am

    I’ve implemented a workaround. On pages that are NOT the base URL, I’ve had them reference themselves in a session variable, as follows:

    if(!$this->facebook->getUser())
    {
      // Set a session var <---
      $_SESSION['redirect_state'] = current_url();
      //NOT LOGGED IN 
       $params = array(
          'scope' => 'email, publish_stream, user_photos, status_update',
          'redirect_uri' => base_url(), // <-- Changed this back to base url.
        );  
        $auth_url = $this->facebook->getLoginUrl($params);  
        $auth_text = "Log In";
    } 
    else 
    {
        //LOGGED IN         
        $fbid = $this->facebook->getUser();
        $fbid = $fbid;
        $auth_url = "https://www.facebook.com/logout.php?confirm=1&next=".urlencode(base_url().'logout/')."&access_token=".$this->facebook->getAccessToken();
        $auth_text = "Log Out";
    }
    
    <a href="<?=$auth_url;?>" class="btn btn-primary"><i class="icon-user"></i> <?=$auth_text;?></a>
    

    Then, the login script will redirect to the app’s base URL. In the base URL, I’ve place a little code checking for the presence of $_SESSION[‘redirect_state’], then kill it, then redirect:

    // Is this a redirect from a another page's login?
        if((isset($_SESSION['redirect_state'])))
        {
            $redir_page = $_SESSION['redirect_state'];  
            unset($_SESSION['redirect_state']);
            redirect($redir_page);
            exit;
        }
    

    The user is now redirected back to the page they logged in from. Because the FB user is logged in, the redirect session variable will not be set, and if the user heads home, the home page won’t redirect weirdly as, again, the redirect session variable is not set.

    I hope this helps someone else out. I’m surprised I haven’t found anyone else talking about this issue, too 🙂

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

Sidebar

Related Questions

I currently have a very simple MySQL database (articlesDB) with 1 table (articles) and
Very simple + silly question: Does clojure provide multi maps? I currently have something
I have a very simple interface which needs to communicate between processes. It's currently
I have a very simple JavaScript/jquery code which won't just work correctly. The problem
I am currently updating a webpage that has some very simple data displayed in
I'm trying to build a simple website with login functionality very similar to the
I currently have a very simple class: public class Music { private Sequence sequence;
Im currently making a very simple WebApp on a Website using ASP.NET Framework using
In cocos2D I currently have a very simple particle emitter initialized like this: turnEmitter
I have a mysql database that is currently running very slow. There are a

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.