什么会导致双页请求? [英] What can cause a double page request?
问题描述
我目前正在调查我网站上的重复请求问题.并不是所有的时间,但有时,请求的页面实际上会加载两次……这实际上不是问题,直到它位于带有PHP的页面上,该页面根据请求(我的跟踪脚本)将内容插入到我的数据库中.
I am currently investigating a double request problem on my site. Not all the time, but sometimes, a requested page will in fact load twice...which is not a problem really until it is on a page with PHP that inserts stuff into my db on request (my tracking script).
我已经阅读到图像标签中的src为空,而CSS背景中的url()为空可能会导致该页面被请求两次.
I have read that an empty src in an image tag, and an empty url() in a css background could potentially cause the page to be requested twice.
但是,我找不到任何问题.
However, I can't find any problems with those.
还有其他可能导致这种情况的原因吗?
Is there anything else that could be causing something like this?
回答我的情况
经过大量研究,结果证明,就我而言,第二个请求来自用户代理"Mediapartner-Google".我开始注意到,在放有Adsense广告的网页上,我自己访问网页后的几秒钟内,就会期望该抓取工具进行二次访问.
After some extensive research, it turns out that in my case specifically, the second request has been coming from the user agent "Mediapartner-Google". I began to notice that on pages that serve an Adsense ad, I could expect a secondary visit from this crawler within seconds after I visit the page myself.
在没有Adsense广告的网页上似乎不会发生这种情况.
This doesn't seem to be happening on pages without Adsense ads.
我将在下面标记一个答案,因为在大多数情况下,这些都是需要检查的正确内容.
I am going to mark an answer below, because it seems like for most situations, those are the correct things to check.
推荐答案
我以前见过的原因:
-
缺少样式表或图像
Missing stylesheet or image
如果您要验证HTML等,则Chrome/Firefox的Web开发人员插件有时会请求两次.
Web developer addon for Chrome/Firefox sometimes requests things twice if you're validating HTML etc.
有时候很难找到重复请求的根本原因.
Sometimes it's just too difficult to track down the root cause of a double request.
无论哪种方式,您都应该不通过GET请求更改数据库状态(或会话状态).您应该在没有postdata的情况下运行的唯一SQL查询是SELECT.即使表单仅包含一个提交按钮,也应使用表单来完成所有更新和插入.
Either way, you should NOT be changing database state (or session state) through a GET request. The only SQL query you should be running without postdata is SELECT. All updates and inserts should be done using forms, even if the form consists only of a submit button.
这篇关于什么会导致双页请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!