2012-02-25 12 views
0

更新:facebook connectでログイン2

ここでは、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で暗号化され

すべてのヘルプは、あなたが任意のより多くの情報が必要な場合は、単に尋ね、高く評価されるだろう:)

-Brad私の前の質問facebook registration connect


私は私のレジスタページを設定する助けを求めました。さて、私は今これを成功させましたが、ユーザーがFacebookにログインできるようにする必要があります。これを行うにはフェイスブックのログインボタンを使いたいと思っていました。ログインボタンをクリックすると、登録されていないことが検出され、登録ページにリダイレクトされます。

どのようなコードを使用しますか?あなたは特別な情報を知る必要がありますか?

+0

[PHPのサイトでのFacebookの統合]の可能な複製(http://facebook.stackoverflow.com/questions/7775079/facebook-integration-in-a-php-site) – DMCS

答えて

1

あなたが達成しようとしていることをカバーするこの記事を見てください。 Facebook Integration in a PHP site

+0

私は非常に混乱していることがわかりました私の登録コードで自分の投稿を更新し、可能であれば、ユーザーが登録されていればログインするためにインデックスに追加するものを教えてくれますか?ありがとう:) –

+1

私はあなたがコードにステップする前にこれを論理に分解することを検討すべきだと思います。 Facebookのセッションをチェックしてください(まだPHPで何もせずにFacebook Connect JSでこれを行うこともできます)。セッションが存在する場合は、そのセッションを検証して、ユーザーのアクセストークンを取得できることを確認し、UIDを参照します(https://graph.facebook.com/me/?fields=id&access_token= {あなたのユーザテーブルにそのUIDが存在するかどうか確認してください。存在していれば登録されて認証方法に進みます。存在しない場合は登録されずに処理されます。 –

+0

私は実際にどのように実際にコーディングするのかについてはまだわかりません...実際にはこれがかなり重要なので、見ていると助けてもらえますか? –