Facebook注册连接 [英] Facebook Registration Connect

查看:176
本文介绍了Facebook注册连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:



Ok,所以我已经解决了我以前的问题(除了我不知道如何补丁的SQLinjection,但现在它不重要)但是我需要让它检测到男性或女性,并从中剥离一些角色...这是我为此做的代码



我在这里定义了变量: p>

  $ gender = $ response [registration] [gender]; 

然后我在这里定义newgender

  $ new_gender =F; 

然而,我然后添加了一个if语句,该语句应该是检测是否为Male,并将其更改为 ($ gender =Male){
$ new_gender =M;
}

代码似乎只是忽略if语句,因为它始终呈现为F为女性。 (我需要代码这样或类似的替代方法,因为sql数据库的工作方式需要1个字母长,所以只有M或F。



我的第二个问题是注册时间显示在数据库中,但是如果有人可以解决这个问题,我会更新它与我的其他问题。



非常感谢,



Brad



当用户点击Facebook注册时,我一直在尝试这样做,它将信息添加到我的数据库中。我收到一个错误,所以不知道该怎么办...这是代码,请以任何方式帮助我。

 <?php 
define('FACEBOOK_APP_ID','276105599128518');
define('FACEBOOK_SECRET','mysecretappidhere');

function parse_signed_request($ signed_request ,$ secret){
list($ encoded_sig,$ payload)= explode('。',$ signed_request,2);

//解码数据
$ sig = base64_url_decode($ encoded_sig);
$ da ta = json_decode(base64_url_decode($ payload),true);

if(strtoupper($ data ['algorithm'])!=='HMAC-SHA256'){
error_log('未知算法,预期的HMAC-SHA256');
返回null;
}

//检查sig
$ expected_sig = hash_hmac('sha256',$ payload,$ secret,$ raw = true);
if($ sig!== $ expected_sig){
error_log('Bad Signed JSON signature!');
返回null;
}

return $ data;
}

函数base64_url_decode($ input){
返回base64_decode(strtr($ input,'-_','+ /'));
}

if($ _REQUEST){
echo'< p> signed_request内容:< / p>';
$ response = parse_signed_request($ _ REQUEST ['signed_request'],
FACEBOOK_SECRET);
// $ no_longer_needed_but_save_for_backup = explode('',$ name,2);
// $ dunno = $ name_arr [0];
// $ dunno = isset($ name_arr [1])?$ name_arr [1]:'';
// $ Location_Array = $ response [registration] [location] [name];

$ uname = $ response [registration] [username];
$ rname = $ response [registration] [name];
$ seckey = $ response [registration] [seckey];
$ email = $ response [registration] [email];
$ password = $ response [registration] [password];
$ gender = $ response [registration] [gender];
$ ip_last = $ _SERVER ['REMOTE_ADDR'];
$ sessionKey ='RevCMS - '。rand(9,999)。'/'。substr(sha1(time())。'/'。rand(9,9999999)。'/'。rand(9,9999999 ) '/' 兰特(9,9999999),0,33)。;

//连接到数据库
mysql_connect('localhost','root','mypasswouldbehere')或死(MySQL错误:mysql_error());
mysql_select_db('phoenix3')或死(MySQL错误:mysql_error());

//插入用户表
$ result = mysql_query(INSERT INTO users(id,username,real_name,password,mail,auth_ticket,rank,credits,vip_points,activity_points,activity_points_lastupdate,看,性别,座右铭,acount_created,last_online,online,ip_last,ip_reg,home_room,respect,daily_respect_points,daily_pet_respect_points,newbie_status,is_muted,mutant_penalty,mutant_penalty_expire,block_newfriends,hide_online,hide_inroom,mail_verified,vip,volume,seckey)
VALUES
(NULL,'$ uname','$ rname','$ password','$ email','$ sessionKey','8','10000','0','0' 0',' - ','$ gender','I< 3 Tropical-Resort','time()','.time()。','0','$ ip_last','$ ip_last' '8','0','3','3','0','0','0','0','0' ','100','$ seckey'));
if($ result){

echoshould /'ve stored;
// GOT RESULTS
}
else
{
echoerror;
//存储
中的错误
}
else
{
echo'$ _REQUEST为空';
}
?>

Yours,
Brad

解决方案

ceejayoz修复问题,回应 echo mysql_error(); 解决问题,因为它告诉你所有的mysql问题。为了解决性别问题,我需要将其从男性缩短为M或女性到F,只需使用PHP的substr,例如...

  $ gender = substr($ fbgender,-4,1); 

感谢所有帮助的人,
-Brad


Updade:

Ok so I've fixed my previous problem (Besides the SQLinjection which I'm not sure how to patch but for now it's unimportant) however I need to get it to detect Male or Female and strip some characters from it too... This is the code I did for that

I defined the variable here:

$gender = $response["registration"]["gender"];

I then defined newgender here

$new_gender = "F";

However I then added an if statement which was supposed to detect if it was Male and change it to "M"

if($gender == "Male"){
$new_gender = "M";
}

The code seems to be simply ignoring the if statement as it always renders as a F for female. (I need the code this way or a similar alternative because the way the sql database works it needs to be 1 letter long so M or F only.

My second problem is having the registered time show up in the DB but if someone can solve this problem first I'll update it with my other issue.

Many thanks,

Brad

I've been trying to make it so when a user clicks register with facebook it adds there information into my database. I'm getting an error however so not sure what to do... Here's the code, please help me in any way you can.

    <?php
define('FACEBOOK_APP_ID', '276105599128518');
define('FACEBOOK_SECRET', 'mysecretappidhere');

function parse_signed_request($signed_request, $secret) {
  list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

  // decode the data
  $sig = base64_url_decode($encoded_sig);
  $data = json_decode(base64_url_decode($payload), true);

  if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
    error_log('Unknown algorithm. Expected HMAC-SHA256');
    return null;
  }

  // check sig
  $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
  if ($sig !== $expected_sig) {
    error_log('Bad Signed JSON signature!');
    return null;
  }

  return $data;
}

function base64_url_decode($input) {
    return base64_decode(strtr($input, '-_', '+/'));
}

if ($_REQUEST) {
  echo '<p>signed_request contents:</p>';
  $response = parse_signed_request($_REQUEST['signed_request'], 
                                       FACEBOOK_SECRET);
//$no_longer_needed_but_save_for_backup = explode(' ',$name,2);
//$dunno = $name_arr[0];
//$dunno = isset($name_arr[1])?$name_arr[1]:'';
//$Location_Array = $response["registration"]["location"]["name"];

$uname = $response["registration"]["username"];
$rname = $response["registration"]["name"];
$seckey = $response["registration"]["seckey"];
$email = $response["registration"]["email"];
$password = $response["registration"]["password"];
$gender = $response["registration"]["gender"];
$ip_last = $_SERVER['REMOTE_ADDR'];
$sessionKey = 'RevCMS-'.rand(9,999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);

// Connecting to database
mysql_connect('localhost', 'root', 'mypasswouldbehere') or die("MySQL Error: " . mysql_error());
mysql_select_db('phoenix3') or die("MySQL Error: " . mysql_error());

// Inserting into users table
$result = mysql_query("INSERT INTO users (id, username, real_name, password, mail, auth_ticket, rank, credits, vip_points, activity_points, activity_points_lastupdate, look, gender, motto, acount_created, last_online, online, ip_last, ip_reg, home_room, respect, daily_respect_points, daily_pet_respect_points, newbie_status, is_muted, mutant_penalty, mutant_penalty_expire, block_newfriends, hide_online, hide_inroom, mail_verified, vip, volume, seckey) 
VALUES 
(NULL, '$uname', '$rname', '$password', '$email', '$sessionKey','8', '10000', '0', '0', '0', '-', '$gender', 'I <3 Tropical-Resort', 'time()', ' . time() . ', '0', '$ip_last', '$ip_last', '8', '0', '3', '3', '0', '0', '0', '0', '0', '0', '0', '1', '0', '100', '$seckey')");
if($result){         

echo"should/'ve stored";
// GOT RESULTS
}
else
{
echo "error";
// Error in storing
}
}
else 
{
echo '$_REQUEST is empty';
}
?>

Yours, Brad

解决方案

ceejayoz fixed the issue, echoing echo mysql_error(); solves the issue as it tells you ALL the mysql problems you have. To fix the gender issue which was I needed to shorten it from Male to "M" or Female to "F" just use PHP's substr so example is...

$gender = substr("$fbgender", -4, 1);

Thanks everyone who helped, -Brad

这篇关于Facebook注册连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆