Facebook注册连接

时间:2012-02-23 01:00:30

标签: php mysql facebook registration connect

Updade:

好的,所以我已经修复了我之前的问题(除了SQLinjection,我不知道如何修补,但现在它不重要)但是我需要让它来检测男性或女性并从中剥离一些字符。 ..这是我为此做的代码

我在这里定义了变量:

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

然后我在这里定义了newgender

$new_gender = "F";

但是我添加了一个if语句,该语句应该检测它是否为男性并将其更改为“M”

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

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

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

非常感谢,

布拉德

我一直试图这样做,当用户点击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); 

  // 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';
}
?>

此致, 布拉德

1 个答案:

答案 0 :(得分:1)

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

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

感谢所有帮助过的人, -Brad