本文介绍了Internet Explorer 8不会为ajax请求传递会话cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的php应用程序,它适用于除IE8 beta 2之外的所有浏览器,当我尝试使用Ajax调用(jQuery post方法)更新表字段时出现问题。使用IE8调试器我发现IE8不发送会话cookie,因此php脚本重定向到登录页面而不是执行请求的操作。

I have simple php application, it works on all browsers except on IE8 beta 2, problem occurs when I try to update table field using Ajax call (jQuery post method). Using IE8 debugger I figure out that IE8 doesn't send session cookie so php scripts redirects to login page instead of executing requested action.

我该怎么做才能使这项工作。

What can I do to make this work.

编辑:
我没有提及我正在使用Code Igniter,因此我通过将Code Igniter默认会话实现替换为本机问题来解决此问题。代码点火器默认会话实现使用cookie来存储所有数据。

I haven't mention that i was using Code Igniter so i have solved this problem by replacing Code Igniter default session implementation with native one. Code igniter default session implementation uses cookie to store all data.

推荐答案

昨天我遇到了类似的问题并找到了解决办法。我希望这也能帮助别人。

Yesterday I had similar problem and found the solution. I hope this will help someone else also.

问题:假设有一个网站 www.somewebsite.com ,其中有IFRAME来加载我的php文件服务器, www.myserver.com/welcome.php 。网站加载成功以及我的欢迎页面,它显示了类似Hello Bob的内容,因此它成功找到了用户并登录了他。

Problem: Suppose there's a website www.somewebsite.com and IFRAME inside it whcih loads php file from my server, www.myserver.com/welcome.php. Website was loading successfully as well as my welcome page and it showed something like "Hello Bob", so it successfully found user and logged him in.

之后我的JavaScript正在制作AJAX调用另一个PHP文件,响应处于未授权状态,因此SESSION数据完全丢失。页面刷新后,一切正常。这只发生在IE8下!

Afterwards my JavaScript was making AJAX calls to another PHP file, and response was kind of in "not authorized" state, so SESSION data was completely missing. After page refresh, everything was working correctly. And this was happening only under IE8!

我认为问题在于将会话cookie发送到服务器,但是当我安装,我发现IE8正在正确发送cookie和PHPSESSID,但服务器有点无法检测到正确的SESSION对象。另一个奇怪的事情是第二次服务器发送了以下标题:

I thought that problem was with sending session cookies to the server, but when I installed Fiddler, I found that IE8 was sending cookies as well as PHPSESSID correctly, but server was kind of unable to detect correct SESSION object. Another strange thing was that 2nd time server sent following header:

P3P:CP =IDC DSP COR ADM DEVI TAIi PSA PSD IVAi IVDi CONi HIS我们的CNT

但是第一次没有。在PHP脚本中手动添加该标题后,一切都像魅力一样!

but first time no. After adding that header manually in PHP script, everything worked like a charm!

然后,当我用Google搜索p3p abracadabra时,我发现了以下网站:

Then, when I googled that "p3p abracadabra", I found following web site:

结论:确保您在设置Cookie的每个页面上发送标题。

Conclusion: Make sure that you're sending the header on every page that sets a cookie.

这与 IE8 + PHP 组合不是 ,在 IE8 + ASP.NET , IE8 + JSP

这篇关于Internet Explorer 8不会为ajax请求传递会话cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 19:54