PHP如何停止Chrome两次加载页面 [英] PHP How to stop Chrome loading a page twice

查看:160
本文介绍了PHP如何停止Chrome两次加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我已经更新并重写了我的问题,以尝试逐步解决此问题.干杯.

Note: I have updated and rewritten my question to try and solve this issue point by point. Cheers.

我遇到了问题,但我不确定如何解决该问题.

I have a problem and I'm not immediately sure how to go about resolving it.

我一直在HTTPS服务器上构建一个安全的登录系统(如果值得的话,它由SSL-labs给出的等级为"A"),并且运行良好,但是今天它拒绝使用进行一些调试后,我发现有些奇怪的事情(在我看来).

I have been building a secured login system on a HTTPS server (with a grade of "A" by SSL-labs, if that's worth anything ), and it works fine, however today it is refusing to log me in, with some debugging I have found something very odd (in my view).

我在网站上进行会话处理时遇到了一些严重问题,不同的页面使用了相同的会话数据(当然)和相同的会话/cookie设置,并且它们彼此之间正确地传递了信息,但是我的浏览器的行为似乎就像有两个浏览器使用相同的会话数据访问相同的网站一样.

I have some serious issues with session handling on the website, the different pages use the same session data (of course) and the same session /cookie settings, and they pass the information between each other correctly, BUT the behaviour of my browser appears to be as if there are two browsers visiting the same websites, using the same session data.

症状-由于我一直与页面生成的会话内容(唯一的哈希令牌)不一致,因此不适合登录表单中保存的相同数据(作为$_POST值),因此我发现只有一行在设置会话值的整个站点中,该行必须运行两次.因此,我在会话中的表单页上将计数器值设置为session['counter'].每次页面加载时,计数器+1.我的问题特别是这样:

Symptoms - Because I have been having inconsistencies with page generated session content (unique hash token) not fitting the same data saved in the login form (as a $_POST value), I was finding that as there is only one line in the whole site that sets the value of the session, this line must be running twice. So I set a counter value in the session, on the form page as session['counter']. each time the page loads, the counter +1's. My problem is specifically with this:

登录页面:

Opens page,  
session hash-string is generated and saved to the post form.
session counter = counter + 1;
Form is filled in.

登录身份验证"页面:

fails to verify the posted hash-string is the same as the session hash
 string, despite there being no other cause for the session values to
 change (well there must be, but I can't see it!)  

但是,然后回到登录页面,我看到计数器=最后一个值+ 2!另外,保存在服务器上的会话文件中记录的计数器值 始终为登录页面上显示的值+1.

But, then going back to the Login Page I see that the counter = last value + 2! Also, the counter value recorded on the session file saved on the server is always +1 to the value displayed on the login page.

一些图片:

登录表单页面:请注意,它位于HTML输出上方,并且是代码上 编辑任何SESSION数据的最后位置 .

Login Form Page: Please note that this is above the HTML output and is the last place on the code where any SESSION data is edited.

输出:

请注意图像1中与计数器有关的数字.

Please note the number relating to the counter in image 1.

我的会话文件,该文件与此特定的浏览器会话相关,并且只有1个会话文件,因为我是该站点上唯一的浏览器.

My session file, this file relates to this specific browser session and only 1 session file as I am the only browser on the site.

字符串CheckDrop是要比较的哈希值,但计数器位于 12 而不是11,该值显示在上面的图像2中.

The string CheckDrop is the hash value to compare but the counter is at 12 rather than 11, which is displayed in image 2 above.

  • 尽管此工作位于子域上,但我的网站已通过HTTPS身份验证.

  • My site is HTTPS authed although this work is on a subdomain.

此问题已经发生了最近3个小时,但不一致,它在今天早40分钟左右就已经神奇地起作用了(就在发布此帖子之前).但是我没有做任何改变环境的事情.

This issue has been happening for the last 3 hours but inconsistently, it magically worked for about 40 minutes earlier today (just before posting this post). but I had done nothing I could see as changing the environment.

我以前已经比较过phpinfo数据和会话设置数据,这些数据在浏览器输出时看起来都是正确的.似乎不是我的设置引起的.

I have previously compared phpinfo data and session setup data it all looks correct at point of browser output. It does not seem to be caused by my settings.

它发生在我PC上的不同浏览器上.

It happens on different browsers on my PC.

经过数小时的调试和解决之后,这似乎是浏览器问题.我已经对页面进行了重命名(其中一个页面在.htaccess中未定义为目录列表页面,这被称为索引,而可能可能导致浏览器将其打开两次).

After spending hours debugging and working through this, it appears to be a browser issue. I have renamed the pages (one page was called index while it was not defined in .htaccess as the directory listing page which may have possibly caused a browser to open it twice).

我清除了所有相关数据:会话/数据库记录/浏览器历史记录,并且遇到了一些问题:

I have cleared all associated data: sessions / database records / browser history, and have come across something:

Firefox现在可以按预期的方式登录,计数器为count + 1并且登录有效,但是在Chrome上,无法在同一页面上进行完全相同的登录,并且浏览器似乎加载了两次,即counter = counter + 2. Chrome还会在每次加载时在数据库中保留两条记录,而不是预期的记录.

Firefox now logs in as expected, the counter is count+1 and the login works, however on Chrome the exact same log in on the same pages does not work and the browser appears to load twice, the counter = counter + 2. Chrome also leaves two records in the database at each load rather than the expected one.

Chrome版本45.0.24 Firefox 42.0版

Chrome version 45.0.24 Firefox version 42.0

页面重复计数,并在 Safari Chrome 上运行脚本两次.在Firefox,Opera和MSIE上,它可以按预期工作.

Page double counts and runs script twice on Safari and Chrome. On Firefox, Opera and MSIE it works as intended.

为什么会这样?

我该如何解决这个问题?

推荐答案

最初的问题是由网页的命名引起的,有一个名为"index.php"的网页,但该页面不是索引,而是"loggedIn" .php"是网站的索引页,如.htaccess

The original issue was caused by the naming of the webpages, there was a webpage named "index.php" but this page was NOT the index, instead "loggedIn.php" was the index page for the site, as defined in .htaccess

拥有一个不是索引的index.php页面似乎使很多浏览器感到困惑.通过重命名所有页面并设置index.php页面(使用PHP标头将用户重定向到合适的页面)(基于是否登录)来解决此问题的一部分.

Having an index.php page that was not an index seemed to confuse a lot of browsers. This [part of] the issue was resolved by renaming all the pages and setting an index.php page that used PHP headers to redirect people to the suitable page (based on if logged in or not) .

Chrome和Safari仍然存在问题.

The issue remained with Chrome and Safari.

长时间阅读了许多有关Chrome的问题之后,该解决方案坦率地令人沮丧,

After a long time reading lots of issues about Chrome, the solution was frankly pathetic,

https://code.google.com/p/chromium/issues/detail?id = 64810

如果某些标记元素不存在,则此链接列出了与此Chrome双重加载问题相关的各种问题.由于上面的页面非常简单,因此应用了很多内容,但是Google Chrome浏览器将静默请求favicon.ico文件,然后如果找不到该文件,则将重新加载该页面,但仅输出第一页(来自Chrome内存缓存).

This link lists various issues relating to this problem of Chrome double loading, if certain markup elements are not present. As my page above are very simple, there wasn't a lot that applied, but Google Chrome will silently request the favicon.ico file and then if it doesn't find it, will reload the page but only output the first page (from Chrome memory cache).

这是Chrome中一个非常愚蠢的错误,它使我花了大部分时间. Safari仍然坚持两次加载PHP脚本,

This is an epically stupid bug in Chrome that has cost me most of a day. Safari still persists in loading the PHP script twice,

这篇关于PHP如何停止Chrome两次加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆