search
HomeBackend DevelopmentPHP TutorialSolution to the problem of session loss caused by cross-domain PHP iframe under IE_PHP tutorial

After a login page is embedded in an iframe by another website, it will become impossible to log in (this situation only exists in IE). The main problem is that the session cannot be saved. I will share my personal solution process with you below. A login page I created today was embedded in an iframe by another website and I couldn't log in (this only happened in IE).

Obviously, the session cannot be saved. But when I open the login page directly in the address bar, everything is normal. How strange.

Searched online. I found that quite a few people have mentioned this issue. The final solution is to add the following code to the login page:
The code is as follows:

header('P3P: CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"'); 
session_start();


Maybe this problem is also related to the fact that my login page uses JavaScript location jump. But there is no in-depth testing research.

Extended reading:
When I was working on the Tencent Friends application today, the tester sent me a work order saying that the application could not be used on IE7. A login timeout error occurred.

The first reaction was that the session was lost.

So I searched online for the IE7 iframe session loss problem. Later I found the following article and solved the problem:

Yesterday, the time diary I made on campus was finally online. On the first day of launch, more than 80 users installed it, but many users reported that the app was unavailable. I used to develop on Firefox (I guess the school staff also used Firefox for review). When I used IE7 to test, I found that all pages other than the homepage could not be opened normally.

After searching a lot of information on the Internet, I found that there is such a problem in IE7: if there are one or more iframe subpages in the page, the session creation in the subpage may not be successful, so the session data cannot be communicated with other pages. shared. When developing on-campus and 51 applications, assuming that iframe is used, you are likely to encounter such a problem. And this problem only exists in IE7 browser. I have tested it in firefox, IE6 and chrome browsers and there is no problem.

The solution is: before running session_start, add the following sentence to the program (taking PHP language as an example), which roughly declares the security level to the browser, so that there will be no problem when the iframe subpage creates a session:

header('P3P: CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"');

In addition, I also learned that if the second-level domain name contains underscores, such as your_domain.yourhost.com, problems may occur when establishing and transmitting sessions.

Some thoughts:

1) After many years, the browser compatibility problem has still not been completely solved, and IE browser is still causing pain and torture to developers.
2) Before releasing the application, it must undergo strict browser compatibility testing, otherwise it may lose the first batch of users of the application.

Other reference articles:

Solve the problem of session loss due to jsessionid failure in iframe
http://618119.com/archives/2007/12/19/48.html

Sso is required to implement the ISMP2.1.1 interface, and the interface defined in ISMP requires calling the sso interface in embedded pages such as iframes. During actual development, it was found that the session could not be transferred normally.

The scenario that reproduces the problem is:

1. Visit site a first: http://192.168.18.2/test.jsp

The code of test.jsp is:


session--www.jbxue.com





Read the passed ssoinfo in sso.jsp and reversely call the ISMP authentication interface,

Generate a session, then put the specified attribute value, session .setAttribute("ssoUser","lizongbo"); The page then redirects to http://192.168.18.3/iframe.jsp

response.sendRedirect(“/iframe.jsp”);

When reading the attribute value of ssoUser in session in iframe.jsp, you will find that it cannot be read.
2. If you first visit the page of 192.168.18.3 and then the page of 192.168.18.2, the iframe embedding at this time can pass the generated jsessionid Cookie.

So the solutions are:

a. Add jsessionid to the url.

For example, redirect to response.sendRedirect(“/iframe.jsp;jsessionid =lizongbo”);
In this case, if the URLs of other connections in the iframe.jsp page do not add jsessionid,

It is also impossible to continue to pass the session, but the href attribute of each hyperconnection is rewritten and added with jsessionid through js on the client side.

Set P3P header information in b.sso.jsp
For example P3P: CP=”CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR”
Or P3P:CP=”CAO PSA OUR”
The java code is:
response.addHeader("P3P","/"CAO PSA OUR/"");

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/739136.htmlTechArticleA login page, after being embedded in an iframe by other websites, cannot log in (this only exists in IE) situation). The main problem is that the session cannot be saved. Here is my personal solution...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
iframe为什么加载慢iframe为什么加载慢Aug 24, 2023 pm 05:51 PM

iframe加载慢的原因主要包括网络延迟、资源加载时间长、加载顺序、缓存机制以及安全策略等。详细介绍:1、网络延迟,当浏览器加载一个包含iframe的网页时,需要发送请求到服务器获取iframe中的内容,若网络延迟较高,那么获取内容的时间就会增加,从而导致iframe加载慢;2、资源加载时间长,资源的大小较大或者服务器响应时间较长时,加载速度会更加明显地变慢;3、加载顺序等等。

微软:每次访问时 Outlook 错误都会下载“TokenFactoryIframe”文件微软:每次访问时 Outlook 错误都会下载“TokenFactoryIframe”文件Apr 19, 2023 am 08:25 AM

当用户通过Safari浏览器访问电子邮件服务时,微软的Outlook正在macOS上下载一个名为“TokenFactoryIframe”的神秘文件。发现Outlook在每次访问时下载的“TokenFactoryIframe”文件的用户现已广泛报告此问题。Outlook每隔几秒或至少在每次访问Apple平台上的Outlook时都会下载此神秘文件。根据我们的调查结果,这似乎是由发布到Outlook的服务器端更新错误引起的问题,与Safari或macOS无关。微软在一份

什么技术可以代替iframe什么技术可以代替iframeAug 24, 2023 pm 01:53 PM

可以代替iframe的技术有Ajax、JavaScript库或框架、Web组件技术、前端路由和服务器端渲染等。详细介绍:1、Ajax是一种用于创建动态网页的技术。它可以通过在后台与服务器进行数据交换,实现页面的异步更新,而无需刷新整个页面,使用Ajax可以更加灵活地加载和显示内容,不再需要使用iframe来嵌入其他页面;2、JavaScript库或框架,如React等等。

Python中iframe是什么意思Python中iframe是什么意思Aug 25, 2023 pm 03:24 PM

Python中iframe是一种HTML标签,用于在网页中嵌入另一个网页或文档。在Python中,可以使用各种库和框架来处理和操作iframe,其中最常用的是BeautifulSoup库,可以轻松地从一个网页中提取出iframe的内容,并对其进行操作和处理。掌握如何处理和操作iframe对于Web开发和数据抓取都是非常有用的。

iframe嵌入播放器是什么iframe嵌入播放器是什么Aug 25, 2023 pm 02:13 PM

iframe嵌入播放器是一种在网页中嵌入视频播放器的技术。嵌入播放器的优点有:1、灵活性,通过使用iframe标签,可以将来自不同来源的视频媒体嵌入到同一个网页中;2、易用性,只需复制并粘贴嵌入代码,即可将播放器添加到网页中;3、可以通过设置参数来控制播放器的外观和行为;4、可以通过使用JavaScript来控制播放器的操作等等。

ie中的iframe是什么意思ie中的iframe是什么意思Aug 24, 2023 pm 05:42 PM

IE中的iframe是一种强大的工具,可以用于在网页中嵌入其他网页或文档,实现页面的分割和内容的展示。通过合理的使用和注意事项,可以充分发挥iframe的优势,提升网页的用户体验和功能性。

什么可以替代iframe什么可以替代iframeAug 24, 2023 pm 01:49 PM

可以替代iframe的有Ajax请求、Web组件、框架和库、跨域通信、使用CSS布局和样式等。详细介绍:1、Ajax请求可以动态加载并显示其他网页或内容,而无需使用iframe,通过使用XMLHttpRequest对象或更现代的fetch API,可以实现异步加载内容,并将其插入到当前网页中的DOM树中,可以避免iframe的安全问题,并且可以更好地控制和操作加载的内容等等。

iframe禁用是什么意思iframe禁用是什么意思Aug 25, 2023 pm 02:05 PM

iframe禁用是指在网页中禁止使用iframe标签的功能。由于一些安全和隐私的考虑,有时候需要禁用iframe标签的使用,常见的禁用方法:1、通过设置X-Frame-Options响应头,表示不允许嵌入到任何iframe中;2、使用Content-Security-Policy,控制是否允许嵌入到iframe中;3、使用JavaScript禁用iframe标签等。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function