关于Iframe如何跨域访问Cookie和Session的解决方法
最近做登录系统的整合,其中遇到的一个最关键的问题为在一个统一的后台里需要无障碍的访问另外一个系统后台,这个系统是第三方提供的一个加过密的系统,后台自动登录接口是自己分析出来的,没有单独提供,当从统一后台通过自动登录接口登录时,系统直接跳转到系统后台首页,后台登录成功后所跳转的URL这里没法指定,控制不了跳转的页面,如果在统一后台里需要链接到这个系统后台的另外一个页面,而非后台默认首页时,也就是将第三方系统后台的菜单功能放到我们这个统一后台里。
对于这样的一个需要,这里会遇到一个问题,为了能正常访问第三方系统的后台栏目,必需确保已经登录该系统,否则会提示用户登录,所以在点击这些菜单链接时,系统必需已经登录。
为了解决这个问题,在页面头部添加了一个不可见的iframe,使其指向到自动登录接口,这个接口如果正常通过浏览器地址栏访问,当用户名和密码验证无误时,会跳转到系统后台首页,由于此时放在了一个不可见的IFRAME中,所以跳转对当前后台页面没有任何影响。按照我的设计方法,系统应该就可以正常使用了。
但,既然说到但了,就说明肯定遇到了问题,不然这里不会来这么大的一个转折的。
但由于这里各系统均属于不同的系统,域名不一样,所以出现了Iframe在IE中,不能正常生成第三方系统Cookie的情况,但在Firefox和其它浏览器中均可生成,所以用IE访问时,总是跳转到登录页面。
这里需要说明一下,这里的第三方系统放在我们自己的服务器上的,只是所有源码加了密!
最后查阅了相关资料后,发现在IE中,为了安全,阻止了通过IFRAME生成第三方域的COOKIE,为了解决这个问题,MS规定只要在HTTP的HEADER头中,设定P3P这个头,就可以通过IFRAME来生成第三方COOKIE了。
PHP中,P3P HEADER 头的设置方法如下:
header(‘P3P: CP=”CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR”‘);
注意:这里的P3P需要添加到第三方域生成Cookie的那个文件才生效,否则无济于事。
这里又有问题了,第三方系统生成COOKIE在后台的一个叫admin.php的页面里生成的,而这个页面又是加过密的,这可怎么办了,想了很久,最后同事灵机一动,说我们可以用我们自己的文件来包含它。靠,这方法太妙了,为什么我就没有想到了,同事真是太有才了,真是佩服的五体投地,当然,我对他这么一佩服,据他说自己当晚也自己佩服了自己一晚上。
所以最后的解决方案为将原来的admin.php文件命名为admin_2.php,然后新建admin.php,最后在这个文件中,添加上面所的P3P这个HEADER头,并再次包含 admin_2.php这个文件,最终代码如下:
header(‘P3P: CP=”CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR”‘);
include “admin_2.php”;
最后,问题彻底解决!
这里标题是COOKIE和SESSION的问题,实质上,基本上是一回事,SEESION最终的保存也是通过SESSION_ID保存到COOKIE源码天空,然后通过这个SID到服务器上找相应的SEESION数据,只要把COOKIE里的SEESION_ID这个COOKIE给删掉,SESSION也就失效了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











As smartphone technology continues to develop, mobile phones play an increasingly important role in our daily lives. As a flagship phone focusing on gaming performance, the Black Shark phone is highly favored by players. However, sometimes we also face the situation that the Black Shark phone cannot be turned on. At this time, we need to take some measures to solve this problem. Next, let us share five tips to teach you how to solve the problem of Black Shark phone not turning on: Step 1: Check the battery power. First, make sure your Black Shark phone has enough power. It may be because the phone battery is exhausted

Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

Tomato Novel is a very popular novel reading software. We often have new novels and comics to read in Tomato Novel. Every novel and comic is very interesting. Many friends also want to write novels. Earn pocket money and edit the content of the novel you want to write into text. So how do we write the novel in it? My friends don’t know, so let’s go to this site together. Let’s take some time to look at an introduction to how to write a novel. Share the Tomato novel tutorial on how to write a novel. 1. First open the Tomato free novel app on your mobile phone and click on Personal Center - Writer Center. 2. Jump to the Tomato Writer Assistant page - click on Create a new book at the end of the novel.

General Matrix Multiplication (GEMM) is a vital part of many applications and algorithms, and is also one of the important indicators for evaluating computer hardware performance. In-depth research and optimization of the implementation of GEMM can help us better understand high-performance computing and the relationship between software and hardware systems. In computer science, effective optimization of GEMM can increase computing speed and save resources, which is crucial to improving the overall performance of a computer system. An in-depth understanding of the working principle and optimization method of GEMM will help us better utilize the potential of modern computing hardware and provide more efficient solutions for various complex computing tasks. By optimizing the performance of GEMM

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

On April 11, Huawei officially announced the HarmonyOS 4.2 100-machine upgrade plan for the first time. This time, more than 180 devices will participate in the upgrade, covering mobile phones, tablets, watches, headphones, smart screens and other devices. In the past month, with the steady progress of the HarmonyOS4.2 100-machine upgrade plan, many popular models including Huawei Pocket2, Huawei MateX5 series, nova12 series, Huawei Pura series, etc. have also started to upgrade and adapt, which means that there will be More Huawei model users can enjoy the common and often new experience brought by HarmonyOS. Judging from user feedback, the experience of Huawei Mate60 series models has improved in all aspects after upgrading HarmonyOS4.2. Especially Huawei M
