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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:32:57+00:00 2026-06-09T21:32:57+00:00

I am learning how to create an app for facebook. What I want is

  • 0

I am learning how to create an app for facebook.
What I want is an app that upon user authorization, collects the user’s info (name, email, bday), insert it to a DB, and autopost in user’s wall.

I have this code, but when I run it the browser tell me that the webpage has resulted in too many redirects.

I have searched a lot and tested many different ways. It seems that this code worked in before, but facebook changed some things. I have tried my best to update it without result. Please take a look at it and guide me to solve it.

Thanks
Here is the code which I saved as index.php in my root folder.

<?php

session_start();

if (!empty($_SESSION)) {
header("Location: index.php");
}
mysql_connect('host', 'username', 'pass');
mysql_select_db('dbname');

# require library
require("src/facebook.php");

# Creating the facebook object
$facebook = new Facebook(array(
        'appId' => 'xxxxxx',
        'secret' => 'xxxxxxxx',
        'cookie' => true
    ));

# check active session
$user = $facebook->getUser();


if (!empty($user)) {
# session active, get user id (getUser()) and user info (api->('/me'))
try {
    $uid = $facebook->getUser();
    $fb_access_token=$user['access_token'];
    $url = $facebook->getLoginUrl(array(
        'req_perms' => 'email,status_update,publish_stream,user_birthday'
            ));
    $user = $facebook->api('/me');
    $photolink = 'http://graph.facebook.com/'.$user['id'].'/picture?type=square';
    $param = array(
        'method' => 'users.getInfo',
        'uids' => uid,
        'fields' => 'pic_big'
    );
    $users_getinfo = $facebook->api($param);
} catch (Exception $e) {

}

if (!empty($user)) {
    # active session, check if already registered the user
    $query = mysql_query("SELECT * FROM users WHERE oauth_provider = 'facebook' AND     oauth_uid = " . $user['id']);
    $result = mysql_fetch_array($query);


    # If not, add it to the database
    if (empty($result)) {
        $query = mysql_query("INSERT INTO users (oauth_uid, oauth_provider, username, first_name, last_name, birthday, email, pic_square) VALUES ('facebook', {$user['id']}, '{$user['name']}', '{$user['first_name']}', '{$user['last_name']}', '{$user['birthday']}', '{$user['email']}', '".$photolink."')");
        $query = mysql_query("SELECT * FROM users WHERE id = " . mysql_insert_id());
        $result = mysql_fetch_array($query);
    }


    // variables in the session 
    $_SESSION['id'] = $result['id'];
    $_SESSION['oauth_uid'] = $result['oauth_uid'];
    $_SESSION['oauth_provider'] = $result['oauth_provider'];
    $_SESSION['username'] = $result['username'];
} else {
    # if error, kill the script
    die("There was an error.");
}

$api_call = array(
    'method' => 'users.hasAppPermission',
    'uid' => $uid,
    'ext_perm' => 'publish_stream'
);
$can_post = $facebook->api($api_call);
if ($can_post) {
    # post it! 
    $facebook->api('/' . $uid . '/feed', 'post', array(
        'message' => 'Wow you can get good prizes!',
        'name' => 'Be happy',
        'description' => 'Tour around the world',
        'caption' => 'Win a full package around the world',
        'picture' => 'http://www.test.com/test',
        'link' => 'http://test.test.com/test/'
    ));
    echo 'Posted!';
} else {
    die('Permissions required!');
}
} else {
# no active session, generate one
$login_url = $facebook->getLoginUrl();
header("Location: " . $login_url);
}

?>
  • 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-09T21:32:58+00:00Added an answer on June 9, 2026 at 9:32 pm

    You are indeed creating a loop in your code. It says that if the user has an active session, redirect him to index.php. From there he’ll be redirected to index.php and so on.

    if (!empty($_SESSION)) {
        header("Location: index.php");
    }
    

    I am not sure what you’re trying to do with this redirect, but it is certainly resulting in a loop.

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

Sidebar

Related Questions

I learning Perl and I want to create a simple application that gets all
I have a simple iPhone app that Im learning and I want to have
I'm looking to create a little app that allows the user to visual and
I'm learning Symfony2 (and OOP) and want to create a service that's available throughout
I am learning how to create an android app and webservice using: Eclipse IDE
As a learning exercise i want to create a simple web api and consume
I'm learning how to integrate facebook api in iphone app. First I visited facebook
I am a php/mysql developer learning android. I am creating an android app that
I'm learning to create an app for WP7 (Mango), and somehow having this problem.
I am learning Scala now and I want to write some silly little app

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.