0

这将很难解释,但我会尽力而为。我有一个 facebook 应用程序(这是一个测验 - 琐事),用户必须使用他们的详细信息“登录”,我正在接收他们的电子邮件,但还要求他们输入电子邮件、手机和地址,我也需要他们在他们可以继续之前喜欢该页面,否则他们将被重定向回同一页面。现在,棘手的部分是。我已经完成了两个账户的设置,当我说两个账户时,我有 15 位 ID 和 10 位 ID 的账户,由于某种原因,具有 10 位 ID 的用户不会通过注册页面。它们被一遍又一遍地重定向到同一页面。这是我的代码:

我也相信这可能不是问题,但我发现这是唯一的区别。

facebook注册页面和liker checker:

session_start();

require 'facebook/src/facebook.php';

//session_unset();  die;

//echo $_SESSION['PRIME_REFERER'];


if(isset($_REQUEST['frame_key']))
{
$ref =     array(1=>'http://localhost/trivia/',2=>'https://apps.facebook.com/testapps/');
$ref = array(1=>'http://localhost/trivia/',2=>'https://apps.facebook.com/testapp/');
$_SESSION['PRIME_REFERER'] = $ref[$_REQUEST['frame_key']];
die;
}

if( $_SERVER['HTTP_HOST'] == 'localhost:81' or $_SERVER['HTTP_HOST'] == 'localhost')
{
$db = 'usermanagement_new';
$host = 'localhost';
$user = 'root';
$password = 'root';
$BASE_URL = 'http://localhost/quiz/';

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

$fb_appId = ID_Goes_Here;
$fb_like = '<iframe src="//www.facebook.com/plugins/likebox.php?    href=https%3A%2F%2Fwww.facebook.com%2Ftest123&amp;width=292&amp;height=100px&amp;colorscheme=dark&amp;show_faces=false&amp;header=true&amp;stream=false&amp;show_border=false&amp;appId=314612832009414" scrolling="no" frameborder="0" style="border:none; color:#fff; overflow:hidden; width:202px; height:100px;" allowTransparency="true"></iframe>';
$is_live = false;
}else{
 $is_live = true;

$db = 'localhost';
$host = 'localhost';
$user = 'localhost';
$password = 'localhost';
$BASE_URL = 'http://localhost/trivia';

$fb_appId = ID_Goes_Here;
$fb_secret = 'secret';

$app_url = 'https://apps.facebook.com/test/';


$fb_api = new Facebook(array(
  'appId'  => $fb_appId,
  'secret' => $fb_secret,
  'cookie' => true,
    ));


$fb_like = '<iframe src="//www.facebook.com/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2Ftest&amp;width=292&amp;height=100px&amp;colorscheme=dark&amp;show_faces=false&amp;header=true&amp;stream=false&amp;show_border=false&amp;appId=495363837220632" scrolling="no" frameborder="0" style="border:none; color:#fff; overflow:hidden; width:202px; height:100px;" allowTransparency="true"></iframe>';

$fb_page_check = true;
 } 


define('BASE_URL',$BASE_URL);

ini_set('display_errors',0);


$dsn = 'mysql:dbname='.$db.';host='.$host;

try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}

require_once 'functions.php';

extract($_REQUEST);


$global_race = array(
    1=>"American Indian / Alaskan Native",
    2=>"Asian / Pacific Islander",
    3=>"Black (not Hispanic)",
    4=>"Hispanic",
    5=>"White (not Hispanic)",
    6=>"Multi-racial",
    7=>"Other",
    8=>"Decline to State",
);

if(strpos($_SERVER['PHP_SELF'],'admin/') === false)
{

$fb_user = $fb_api->getUser();

if ($fb_user) {
  try {
// Proceed knowing you have a logged in user who's authenticated.
$fb_profile = $fb_api->api('/me');

if($_SESSION['USER_ID'] == NULL)
{
    $qry = 'select count(*) as cnt from users where     username="'.$fb_profile['id'].'"  limit 1';
    $sql = $dbh->prepare($qry);
    $sql->execute();
    $data = $sql->fetch();

    if($data['cnt'] == 0)
    {
         $birthDate = explode("/", $fb_profile['birthday']);
         //get age from date or birthdate
         $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y")-$birthDate[2])-1):(date("Y")-$birthDate[2]));

        $fb_data = array($fb_profile['id'],$fb_profile['email'],$fb_profile['first_name'],$fb_profile['last_name'],$fb_profile['location']['name'],
                        $age);

        $qry = 'insert into users set username=?,f_email=?,firstname=?,lastname=?,address=?,age=?';
        $sql = $dbh->prepare($qry);
        $sql->execute($fb_data);
    }

}

$qry = 'select *  from users where username="'.$fb_profile['id'].'"  limit 1';
$sql = $dbh->prepare($qry);
$sql->execute();
$data = $sql->fetch();

if($_SESSION['USER_ID'] != null and isset($_REQUEST['code']))
{
    $_SESSION['USER_ID'] = $data['id']; 
    redirect('index.php');
}

$_SESSION['USER_ID'] = $data['id']; 
//redirect('index.php');

if($_SESSION['USER_ID'] > 0)
{
    $likes_total =array();
    $next = null;

    do  
    {
        if($next)
        $likes = $fb_api->api( '/me/'.$next );
        else
        $likes = $fb_api->api( '/me/likes?fields=id' );

        $likes_total = array_merge($likes['data'],$likes_total);

        $next = $likes['paging']['next'];
        $next_a = explode('/',$next);
        $next = $next_a[count($next_a)-1];
    }
    while($next!='');

    $like_appid = ID_Goes_Here;

    $o_page = array('id'=>$like_appid);
    //echo '<pre>';print_r($likes_total);die;


    if($is_live && (in_array($o_page,$likes_total) == false or $data['school'] == '') and strpos($_SERVER['PHP_SELF'],'facebook_data.php') === false 
        and strpos($_SERVER['PHP_SELF'],'admin/') === false and strpos($_SERVER['PHP_SELF'],'login.php') === false)
//  if($_SESSION['FB_KEY'] == null and (in_array($o_page,$likes['data']) == false or $data['school'] == '') and strpos($_SERVER['PHP_SELF'],'facebook_data.php') === false)
    {
        redirect('facebook_data.php');
    }
    else
    {
        $_SESSION['FB_KEY'] = true;     
    }

}

//  if($_SESSION['FB_KEY'] != null)
//{

//}
    //  $_SESSION['FB_KEY'] = false;


  } catch (FacebookApiException $e) {
error_log($e);
$fb_user = null;
  }
}
elseif($_SESSION['USER_ID'] > 0)
{
session_unset();
redirect('index.php');
}


// Login or logout url will be needed depending on current user state.
if ($fb_user) {

   $fb_logoutUrl = $fb_api->getLogoutUrl();
  //echo Facebook::getLogoutUrl();
} else {
$scope_params_as_array = array('user_likes','user_birthday','email');
$params = array('scope' => $scope_params_as_array);
$paramsd = array(
    'canvas'    => 1,
    'req_perms' => 'email,user_birthday,user_likes,friends_likes,likes',
    'redirect_uri' => $app_url
    );
//$fb_loginUrl = $fb_api->getLoginUrl($params);
$fb_loginUrl = 'https://www.facebook.com/dialog/oauth?    client_id='.$fb_appId.'&redirect_uri='.$app_url.'&state=734ca386665871ba8bf31be410aa62de&canvas=1&fbconnect=0&req_perms=email%2Cpublish_stream%2Cstatus_update%2Cuser_birthday%2C+user_location%2Cuser_work_history';

if(!isset($_REQUEST['code']))
{
    print '<script language="javascript" type="text/javascript"> 

    window.top.location.href = "'.$fb_loginUrl.'";
    </script>';
    die;

    //redirect($fb_loginUrl);
}
}
}

//echo '<pre>';print_r($fb_profile);

我已经替换了id和mysql ofc。

如果有人可以帮助我,我将不胜感激。

编辑:

这里还有一个获取用户名的函数:

function getUser($username = null)
{
global $dbh;
extract($_REQUEST);

if($username == null)
$username = $_SESSION['USER_ID'];

$qry = 'select * from users where username="'.$username.'" limit 1';
$sql = $dbh->prepare($qry);
$sql->execute();
$data = $sql->fetch();

return $data;
}
4

0 回答 0