php Facebook注册连接

yrdbyhpb  于 2023-05-16  发布在  PHP
关注(0)|答案(1)|浏览(134)

更新:
好了,我已经解决了我以前的问题(除了SQLinjection,我不知道如何修补,但现在它是不重要的),但我需要让它检测男性或女性和剥离一些字符从它太…这是我做的代码
我在这里定义了变量:

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

然后我在这里定义了新性别

$new_gender = "F";

然而,我随后添加了一个if语句,它应该检测它是否是Male并将其更改为“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';
}
?>

你的,布拉德

mnemlml8

mnemlml81#

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

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

感谢所有帮助过我的人,-布拉德

相关问题