将POST参数添加到fb:login按钮 [英] Add a POST parameter to fb:login button

查看:283
本文介绍了将POST参数添加到fb:login按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我试图在用户用facebook按钮点击登录时设置一个POST ..这是因为在我制作的代码中,如果你已经注销,但是在Facebook中插入,那么你会在网站中再次被盗...所以,如果你clic注销,你永远不会注销..

Hello im trying to set a POST when the user clicks the login with facebook button.. This is because in the code i made, if you are logged out, but loged in in facebook then you are automatically loged again in the site... so if you clic logout, you never logout..

为了避免这种我试图设置POST,设置经典条件

To avoid this im trying to set a POST , to set a classic condition

 if ( isset ($_POST['fbconnect'])) 

我只需要添加一个隐藏的输入并发送该表格usinf fb:login-button

I just need to add a hidden input and send that form usinf fb:login-button

这里是我试过的。没有运气。

here is what i have tried.. with no luck.

<form  name="fbconnect" method="post">
<input   type="hidden" name="fbconnect" value="fbconnect"  />

 <div id="fb-root"></div>
 <fb:login-button scope='email,user_birthday'></fb:login-button></form>
 <?php
}
?>
 <script>
 window.fbAsyncInit = function() {
 FB.init({
 appId : <?=YOUR_APP_ID?>,
 status : true,
 cookie : true,
 xfbml : true,
 oauth : true,
 });


FB.Event.subscribe('auth.login', function(response) {
 // ------------------------------------------------------
 // This is the callback if everything is ok
  $(this).parents('form').submit();
 });
 };

(function(d){
 var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
 js = d.createElement('script'); js.id = id; js.async = true;
 js.src = "//connect.facebook.net/en_US/all.js";
 d.getElementsByTagName('head')[0].appendChild(js);
 }(document));
</script>

我也试图替换 $(this).parents('form' ).submit(); 带有表格名称的表格,但它可以正常工作

Also ive tried to replace $(this).parents('form').submit(); form with the name of form, but it dosent work either

我也试过这个

<script>
 window.fbAsyncInit = function() {
 FB.init({
 appId : <?=YOUR_APP_ID?>,
 status : true,
 cookie : true,
 xfbml : true,
 oauth : true,
 });


FB.Event.subscribe('auth.login', function(response) {
 // ------------------------------------------------------
 // This is the callback if everything is ok

 var url = "index.php";
var params = "fbconnect=fbconnect";
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
    if(http.readyState == 4 && http.status == 200) {
        alert(http.responseText);
    }
}
http.send(params);


 });
 };

(function(d){
 var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
 js = d.createElement('script'); js.id = id; js.async = true;
 js.src = "//connect.facebook.net/en_US/all.js";
 d.getElementsByTagName('head')[0].appendChild(js);
 }(document));
</script>


推荐答案

更好的做法是在用户使用重定向注销,而不是POST,即:

A better practice would be using a redirect when a user logs out, instead of a POST, i.e:

HTML:

<a onclick="FB.logout">Logout</a>

和Javascript:

and Javascript:

FB.Event.subscribe('auth.authResponseChange', function(response) {
  if (response.status == "connected") {
    // log in login
  }
  else if (response.status != "connected") {
    // logout logic, i.e
    // location.href = "/sessions/logout";
    alert("User has disconnected")
    location.href = "/index.php?fbconnect=fbconnect"
  }
});

如果你坚持帖子,你可以使用jQuery简单地做事:

if you do insist of a post, you can use jQuery to simplfly things:

FB.Event.subscribe('auth.login', function(response) { 
  $.post("index.php", {fbconnect: fbconnect}, function(data, response) {
    alert(data);
  });

});

这篇关于将POST参数添加到fb:login按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆