1

此代码适用于除 Internet Explorer 之外的所有浏览器。

基本上,当重定向发送到 IE 时,它只是再次从我的服务器请求完全相同的 URL,它只是忽略重定向。

使用 Naitik Shah 的 3.1.1 代码

这是代码:

// $g_facebook is declared earlier and given app id and secret
$par[ 'scope' ] = array( 'publish_stream' , // publish to the user's stream
                                 'offline_access' , // access these functions when the user is offline
                                 // 'user_status'    , // get the user's latest status
                                 // 'read_stream'    , // read the user's stream
                                 'email'          , // provides the user's email address
                                 'user_groups'    , // provides the user's groups
                                 // 'sms'            , // send and receive txt w/ user
                                 'publish_actions', // publish scores and achievements
                                 );
header( 'Location: ' . $g_facebook->getLoginUrl( $par ) );
exit( );

这是电线上发生的事情(使用 tcpdump 拾取):

GET /fork HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Accept-Language: en-us
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C)
Accept-Encoding: gzip, deflate
Host: fbar.toolsteam.com
Connection: Keep-Alive
Cookie: PHPSESSID=7f32d7e4acd63696bd8d0998913f608c; PHPSESSID=e30076106b21e40142397219283fd55f

HTTP/1.0 302 Moved Temporarily
Date: Mon, 07 May 2012 07:36:12 GMT
Server: Apache
X-Powered-By: PHP/5.3.10
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=a9f17a1119dc262bef693d2d39a15317; expires=Tue, 07-May-2013 07:36:12 GMT; path=/
Location: http://www.facebook.com/dialog/oauth?client_id=336243633108439&redirect_uri=http%3A%2F%2Ffbar.toolsteam.com%2Ffork&state=b52dd5dd08e0058e28ae8734f269cd77&scope=publish_stream%2Coffline_access%2Cemail%2Cuser_groups%2Cpublish_actions
Content-Length: 0
Content-Type: text/html
X-Cache: MISS from base
X-Cache-Lookup: MISS from base:3128
Via: 1.1 base:3128 (squid/2.7.STABLE9)
Connection: keep-alive

当 IE 看​​到 302 它只是一次又一次地发送原始请求。它从不跟随重定向到 facebook。

如前所述,Chrome 和 Firefox 没有问题。

想法?

4

1 回答 1

1

答案在请求标头中:

Cookie: PHPSESSID=7f32d7e4acd63696bd8d0998913f608c; PHPSESSID=e30076106b21e40142397219283fd55f

此 facebook 身份验证涉及两台服务器,一台是原始网站,第二台是协商 facebook 权限的中间服务器。facebook 服务器是主站点的子域。

结果他们俩都开始了php会话。facebook 服务器的 cookie 在子域范围内,主站点的 cookie 在顶级域范围内。

无论出于何种原因,IE 都无法处理两次向 facebook 服务器的请求发送相同的 cookie - 它处理事务很好,但无论出于何种原因,它只会重新请求相同的 URL 并忽略 302 重定向。IE就是这样。

我在 facebook 服务器上切换了会话变量名称,问题就消失了。

于 2012-09-20T02:23:20.690 回答