PHP Facebook API身份验证工作但看到" CSRF状态令牌与提供的#c;在日志中

时间:2012-06-16 02:21:18

标签: php facebook

我已经找到了追查这个错误的原因。

我的应用程序功能齐全,即使我在错误日志中看到此错误: “CSRF状态令牌与提供的令牌不匹配”

我搜索了这个网站并看到了与使用get loginUrl和.htaccess相关的帖子。

我无法使用loginURL或我的.htaccess查看代码中的问题。我会在这里张贴。

我看到的行为是用户来到我的页面(未登录),我显示登录URL,用户通过Facebook登录,当他们返回状态字符串时,我的错误日志中有4个条目,出现此错误。

options -multiviews
<IfModule mod_rewrite.c>
RewriteEngine On 
RewriteBase /


RewriteRule ^my$ my.php [L,QSA]
RewriteRule ^site-admin$ site-admin.php [L,QSA]
RewriteRule ^admin$ site-admin.php [L,QSA]
RewriteRule ^banned$ banned.php [L,QSA]
RewriteRule ^userlist$ userlist.php [L,QSA]
RewriteRule ^uploadfeatured$ uploadfeatured.php [L,QSA]
RewriteRule ^viewlatest$ viewlatest.php [L,QSA]
RewriteRule ^featured$ featured.php [L,QSA]
RewriteRule ^get$ get.php [L,QSA]

</IfModule>
<IfModule mod_security.c> 
   # Turn off mod_security filtering. 
   SecFilterEngine Off 

   # The below probably isn't needed, 
   # but better safe than sorry. 
   SecFilterScanPOST Off 
</IfModule>





    function getLoginURL()
{
    $facebook = new Facebook(array(
        'appId'  => APP_ID,
        'secret' => SECRET,
        'fileUpload' => true
    ));
    $user = $facebook->getUser();
    if($user && userHasPermissions())
    {
        //user has permissions and is logged in

        $me= $facebook->api('/me'); 
        $con = getConn();   
        $query="select * from users where fb_id='".$user."';";
      $result=mysql_query($query);   
        $result=mysql_query($query);     
      while ($row = mysql_fetch_assoc($result)) 
      {
      $userid =  $row['id'];
        }                                       

      if (mysql_num_rows($result) == 0)
        {
            // Got a newbie, now we need to add him into our db                 
            $query2= "INSERT INTO users (fb_id ,name ,email) VALUES ('".$user."','". $me['name']."','". $me['email']."')";
            $result2=mysql_query($query2);                          
            $facebook->api("/me/feed", "post", array(
            message => "Welcome to XXX - XXX!",
            picture => "http://XXX.us/static/img/XX.png",
            link => "http://XXX.us",
            name => "XXX ",
            caption => "XXX welcomes you!"
            ));
            echo "<script language='javascript'> window.location='http://XXX.us';</script>" ;
        }
        else
        {                           
            $query3 = "UPDATE  users SET  email='". $me['email']. "',access_token='". $facebook->getAccessToken() ."',name='". $me['name'] ."' WHERE  id=". $userid .".;";                                                              
            $result3=mysql_query($query3);                                                                                                  

        }

      return null;
    } 
    else 
    {
        $loginUrl = $facebook->getLoginUrl(
        array('scope' => 'publish_stream,user_photos,offline_access,email'));   

    }
    if($user)
    {
        $access_token = $facebook->getAccessToken();
        $query3 = "UPDATE  users SET  email='". $me['email']. "',access_token='". $facebook->getAccessToken() ."',name='". $me['name'] ."' WHERE  id=". $userid .";";                                                               
        $result3=mysql_query($query3);  
    }
    else
    {

    }
    return $loginUrl;
}

0 个答案:

没有答案