当iframe调用网站时,会话无法正常工作

编程入门 行业动态 更新时间:2024-10-19 18:29:52
本文介绍了当iframe调用网站时,会话无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有第一个网站 www.mydomain1 ,其中使用了PHP会话.没问题,一切正常,当我一页一页地浏览时,我可以访问我的会话变量.

I have a first site www.mydomain1 in which I use PHP sessions. No problem, everything works fine, when I go from page to page, I can access my session variables.

我有第二个站点 www.mydomain1 ,其中显示了我的部分内容通过iframe的第一个网站:

I have a second site www.mydomain1 in which I display part of my 1st site via an iframe:

<iframe src = "www.mydomain1" width = "100%" frameborder = "0" style = "border: 0" allowfullscreen = "allowfullscreen" id = "frameLeonard"> </iframe>

奇怪的是,会话变量不再被识别.我什至没有试图让我的第一个站点从第二个站点访问会话变量(这不是目标,并且正常工作是不正常的),而只是在第一个站点内运行第二个站点.

And there strangely, the session variables are no longer recognized. I'm not even trying to get my 1st site to access the session variables from the 2nd site (that's not the goal and it's normal that it doesn't work) but just run the 2nd site inside the 1st site.

奇怪的是,它在一年前仍在工作.是否有任何升级可以解释该问题?

Strangely, it was still working a year ago. Has there been any upgrade that would explain the problem?

提前感谢您的照明!

推荐答案

现在我找到了原因,chrome显示了这种行为.对于版本80(2020年2月),它具有默认情况下的SameSite Cookie"默认情况下启用此功能,这意味着在iframe中包含外部页面(不同的域)将终止其会话.

Now I found the reason, chrome shows this behaviour. With version 80 (Feb. 2020) it has it's "SameSite by default cookies" enabled as default, which means that including external pages (different domain) inside an iframe, will kill their sessions.

为防止这种情况,您可以禁用默认情况下,SameSite Cookies"在chrome://flags中注意:这可能是一个安全问题(但现在已经解决了我的问题)

For preventing this, you can disable "SameSite by default cookies" in chrome://flags Beware: This might be a security issue (but solved my problem for now)

否则,如果使用的是PHP 7.3或更高版本,则可以在PHP中的 session_start()之前添加以下(或同时)以下 ini_set():

Otherwise - if using PHP 7.3 or newer - you could add one (or both) of the following ini_set() in your PHP before session_start():

ini_set('session.cookie_samesite', 'None'); session_set_cookie_params(['samesite' => 'None']);

您在这里获得更多详细信息: blog.heroku/chrome-changes-samesite-cookie#prepare-for-chrome-80-updates

Here you get further details: blog.heroku/chrome-changes-samesite-cookie#prepare-for-chrome-80-updates

更多推荐

当iframe调用网站时,会话无法正常工作

本文发布于:2023-11-01 12:47:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549374.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   工作   网站   iframe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!