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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:00:55+00:00 2026-06-05T03:00:55+00:00

I am trying to play around with authentication for an app I am working

  • 0

I am trying to play around with authentication for an app I am working on atm. The app will be tab based. I am now strugling with an infinite loop while trying to authenticate the app. The authentication procces is like this:

if (!isset($_REQUEST["code"])) {
            $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
            $dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
                    . $appId . "&redirect_uri=" . urlencode($redirectUri) . "&state="
                    . $_SESSION['state'];

            echo("<script> top.location.href='" . $dialog_url . "'</script>");
            exit;
        }

        if ($_REQUEST['state'] == $_SESSION['state']) {
            $code = $_GET["code"];
            $token_url = "https://graph.facebook.com/oauth/access_token?"
                    . "client_id=" . $appId . "&redirect_uri=" . urlencode($redirectUri)
                    . "&client_secret=" . $appSecret . "&code=" . $code;

            $response = @file_get_contents($token_url);
            $params = null;
            parse_str($response, $params);

            $graph_url = "https://graph.facebook.com/me?access_token="
                    . $params['access_token'];

            $user = json_decode(file_get_contents($graph_url));
            echo("Hello " . $user->name);
        } else {
            echo("The state does not match. You may be a victim of CSRF.");
        }

The $redirectUri is now set to “http://www.facebook.com/pages/DummyPage/PAGE_ID?sk=app_APP_ID&#8221; but once I am redirected back, after the authentication, I am unable to read $_GET or $_REQUEST arrays because they are empty (even though I can see that the url I get after auth. has “code”, “state” etc. in it). This will result in infinite loop, because I am stuck in the first if statement.

What is interesting here is that when I change the $redirectUri to the url where my app sits in – right now I am testing it on localhost – so I put in “http://localhost/test/index.php&#8221; – the infinite loop wont happen because I am redirected outside facebook and I can read from $_GET array.

I need to stay on facebook when authenticating. Do you guys know how to get around this problem?

  • 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-05T03:00:56+00:00Added an answer on June 5, 2026 at 3:00 am

    Please use the Facebook PHP SDK for things that you’re trying right now.

    It makes the thing a lot easier and you probably get to your goal in less time.

    OR

    if you want to do manually and interested in learning the internals, you need to check page tab authentication and signed request

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

Sidebar

Related Questions

I'm trying to play around with some music clustering algorithms, and I thought that
Hi I am trying to play around with async.parallel and here is my code
I'm having a bit of a play around with IIS7, just trying to catch
I'm trying to play around with a RatingBar, but something is really wrong. <?xml
I'm brand spanking new to WPF and am trying to play around with projects
Trying to code a basic text editor to play around with Java's file objects
I am starting out to play around with Ruby and trying to make a
I am trying to set up a development environment to play around with developing
I am trying to customise audio tag in HTML5. To play around with controls
I'm trying to play around with an Android Service but the more I play

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.