php - 用facebook登录connect 2

标签 php mysql facebook login connect

更新:

这是单击我的Facebook登录按钮发送给的页面用户。

<?php
define('FACEBOOK_APP_ID', 'XXXX');
define('FACEBOOK_SECRET', 'XXXX');

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) {
  $response = parse_signed_request($_REQUEST['signed_request'], 
                                       FACEBOOK_SECRET);

$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'];
$time = time();
$sessionKey = 'RevCMS-'.rand(9,999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
$newgender = substr("$gender", -4, 1);
$newpass = md5($password); //This will encrypt the password with md5, if you're not using RevCMS ensure your CMS uses md5 or change it.
$newseckey = md5($seckey); //This will encrypt the security key with md5.
// Connecting to database
mysql_connect('localhost', 'root', 'habbo123');
mysql_select_db('phoenix3');

// 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, account_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', '$newpass', '$email', '$sessionKey','3', '10000', '0', '1000', '0', '-', '$newgender', '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', '$newseckey')");
if($result){         
//Begin redirect to logged in page
header( 'Location:http://tropical-resort.org/me' );
// End redirect
}
else
{
//Un-hash this code if you're getting errors, if the error is to do with mysql it will tell you whats wrong. (Be sure to hash the redirect if you un-hash this.)
#echo mysql_error();
#echo "<br>"; echo "\"$newgender\"";
// Heres the redirect page, if you like you could send them to an error page because they'll only be sent this link if there was an error registering them.
header( 'Location:http://tropical-resort.org/index' );
}
}
else 
{
//$_REQUEST was left empty, this means at least 1 field was blank however it's more than likely they tried to go direct to this page.
?><script>alert("You left a field out, Please click back and make sure to fill everything in.")</script>
<form>
<input type="button" value="Go Back" onClick="history.go(-1);return true;">
</form>
<?php
}

?>


我现在需要做的是在索引中添加一个按钮,上面写着“登录”,如果他们单击该按钮,它将尝试使用其Facebook登录到我的网站;如果用户没有帐户,则应将其重定向到我的帐户。注册脚本,否则它将自动登录并重定向到登录屏幕。

您可能需要了解的信息:

登录的密码字段已使用md5加密

任何帮助将不胜感激,如果您需要更多信息,请询问:)

-布拉德



在上一个问题facebook registration connect中,我要求您设置我的注册页面。好吧,我现在已经成功地做到了,但是现在我需要做到这一点,以便用户也可以使用facebook登录。为此,我希望使用FaceBook登录按钮,如果他们单击登录并且检测到未注册,它将重定向到注册页面,否则它将登录。

我将使用什么代码(示例)?您需要知道任何特殊信息吗?

最佳答案

看一下这篇文章,其中涵盖了您要实现的目标。 Facebook Integration in a PHP site

关于php - 用facebook登录connect 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9447921/

相关文章:

具有多个分组或排序的 mysql 查询优化

javascript - 无法从 facebook javascript 登录 api 获取用户 ID

javascript - 通过 Facebook Javascript SDK 获取电子邮件

php - 在 PHP 中包含文件时,注释会影响吗?

mysql - “information_schema.character_sets”不存在

php - 实现没有刷新警报的 PHP 和 MySQL

php - "Cannot convert value to string"取数据时(belongsToMany关系)

Android Facebook 登录屏幕没有键盘

PHP 获取没有扩展名的当前页面名称?

php - TXT 到 SQL,完成后自动删除该行 txt