douvcpx6526 2013-09-23 13:22
浏览 70

如果用户ID有10位数,则应用程序遇到问题 - 可能导致什么?

This will be very hard to explain, but i will do my best. I have a facebook application (it's a quiz - trivia), where users has to "sign in" with their details, i'm picking up their emails, but also requiring them to input the email, cellphone and address, also i require them to like the page before they can proceed, otherwise they are redirected back to the same page. Now, the tricky part is. I have went through the settings of both accounts, when i say both accounts, i have accounts with 15 digits ID and 10 digits ID, for some reason, the users with 10 digits ID won't pass the registration page. They are being redirected over and over to the same page. Here is the code i have:

I also believe that might not be a problem, but i have found it as only difference.

facebook registration page and 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);

I have replaced the id's and mysql ofc.

If anyone can please help me, i'll be most grateful.

Edit:

Also here's a function that get's username.:

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;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题