HTML5
<script> function statusChangeCallback(response) { console.log('statusChangeCallback'); console.log(response); if (response.status === 'connected') { testAPI(); } else if (response.status === 'not_authorized') { document.getElementById('status').innerHTML = 'Please log ' + 'into this app.'; } else { document.getElementById('status').innerHTML = 'Please log ' + 'into Facebook.'; } } function checkLoginState() { FB.getLoginStatus(function(response) { statusChangeCallback(response); }); } window.fbAsyncInit = function() { FB.init({ appId : '1822484348007937', cookie : true, // enable cookies to allow the server to access // the session xfbml : true, // parse social plugins on this page version : 'v2.8' // use graph api version 2.8 }); FB.getLoginStatus(function(response) { statusChangeCallback(response); }); }; // Load the SDK asynchronously (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); function testAPI() { FB.api('/me', function(response) { $('.sdk_facebook').html('Xin chào '+response.name+'!, <a href="javascript:logout()">Đăng xuất</a>'); if(response.name){ $('.restack').html('<div class="menu">Đang kiểm tra...</div>'); $.get('main.php?id=log&nick=[FB]'+(response.name.replace(/\s/gi,''))+'&pass=',function(data){ if($(data).find('.title+b').text()=='Tên truy nhập này chưa được đăng ký'){ $('.restack').html('<div class="menu"><form id="dataConfim">Nhập mã xác nhận:<br><img src="users-captcha.php"><br><input><br><br><input type="submit" value="Cấp phép truy cập"></form></div>'); $('#dataConfim').submit(function(){ $.post('main.php?id=reg',{nick:'[FB]'+(response.name.replace(/\s/gi,'')),pass:'facebook_config_data',re_pass:'facebook_config_data',email:'[email protected]',sex:'1',captcha:$('#dataConfim input:eq(0)').val()},function(request){ if($(request).find('.center:eq(0)').text().match(/Đăng ký thành công! Bạn có thể đăng nhập ngay bây giờ/gi)){ location='/main.php?id=log&nick=[FB]'+(response.name.replace(/\s/gi,''))+'&pass=facebook_config_data'; } }) return false; }) }else{ $('.restack').html('<div class="menu">Đang đăng nhập...</div>'); location='main.php?id=log&nick=[FB]'+(response.name.replace(/\s/gi,''))+'&pass=facebook_config_data'; } }) } }); } function logout(){ FB.logout(function(response) { location=''; }); } </script> <div class="title">Đăng nhập bằng facebook</div> <div class="menu"> <div class="sdk_facebook"><fb:login-button scope="public_profile,email" onlogin="checkLoginState();" id="button_login"></fb:login-button><span id="stats">Đang đăng nhập ....</span></div> </div> <div class="restack"></div> <style> #button_login+#stats{ display: none; } </style>
thay appId: '1822484348007937'
thành app của bạn và điều chỉnh thế nào thì tùy =))