<a class="fb_login_btn" onclick="fb_login();return false;"><img src="/image/fb_login.png" border="0" alt=""></a> <script> function handle_fb_data(response){ FB.api('/me', function(response) { console.log('Successful login for: ' + response.name); console.log(' : '+JSON.stringify(response)); // alert(' : '+JSON.stringify(response)); $.ajax({ type: 'post', url: '/do/reg/fb', data: response, success: function(msg) { console.log(msg); if ((msg=='')||(msg=='')){window.location.reload();} }, error: function(){} }) }); } function fb_login(){ FB.getLoginStatus(function(response) { if (response.authResponse) { console.log('Welcome! Fetching your information.... '); handle_fb_data(response); } else { console.log(' , '); FB.login(function(response){ if (response.authResponse) { console.log('Welcome! Fetching your information.... '); handle_fb_data(response); } else { console.log(' '); } }); } }, { scope: 'email,id' }); } window.fbAsyncInit = function() { FB.init({ appId : '{ ID }', 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 }); }; // 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')); </script>
public function fb(){ if (($this->session->userdata('logged_in') != true) ){ // 1. , . // 2. , , FB_ID // , // 3. , // , , .. "" $query = $this->db->get_where('users', array('fb_id' => $_POST['id'])); if ($query->num_rows() > 0) { foreach ($query->row_array() as $key => $value) { $userdata[$key] = $value; } $userdata["logged_in"] = true; //, - , , if ($this->session->userdata('bet_code_last') != false) { $data = array( 'start_user_id' => $userdata['id'] ); $this->db->where('bet_code', $this->session->userdata('bet_code_last')); $this->db->update('bet', $data); $this->session->sess_destroy(); } $this->session->set_userdata($userdata); echo ''; } else { $data = array( 'fb_id' => $_POST['id'], 'lang' => 'en', 'name' => $_POST['name'], ); // , , if( preg_match('/[-]/i', $_POST['name']) ){$data['lang']='ru';} $this->db->insert('users', $data); // , ;) $data["logged_in"] = true; $this->session->set_userdata($data); echo ''; } }else{echo ' ';} }
Source: https://habr.com/ru/post/325514/
All Articles