使用友好的 URL 来避免缓存问题
在我的应用程序 (*) 中,我有时需要打开(在默认用户浏览器中)带有一些参数的 URL。
在某些计算机上,我遇到了缓存问题,即使我发送不同的参数,浏览器也会使用旧参数打开页面。
我尝试添加时间戳作为第一个参数:
- 例如: http://www.mySite.com/myPage.php?pXXX=XXX&p1=param1&p2=param2&p3=param3
- 其中 XXX = Now.ToString("ssmmHHddMMyy")
但在某些计算机上它仍然没有解决问题。
我想知道使用友好的 URL 是否有助于避免所有用户、所有浏览器、所有默认设置等的缓存问题,
[我使用友好 URL 的来源:
- http:// /techie-buzz.com/how-to/create-seo-friend-urls-using-mod-rewrite-and-php-part-1.html
- http ://techie-buzz.com/tips-and-tricks/create-seo-friend-urls-with-mod-rewrite-and-php-part-ii.html
]
您知道吗任何缺点使用这种传递参数的方法?
谢谢,
Atara。
(*) 我的应用程序是一个 exe 文件 (VB .Net) 应用程序的菜单选项之一是使用用户默认浏览器打开 URL:
'-- Create temporary *.url file and open it
Try
Dim line1 As String = "[InternetShortcut]"
Dim line2 As String = "URL=" & sUrl
Dim dst As String = GetSystemPathTemp() & "myAppTemp.url"
Dim sw As New System.IO.StreamWriter(dst, False)
sw.WriteLine(line1)
sw.WriteLine(line2)
sw.Close()
System.Diagnostics.Process.Start(Chr(34) & dst & Chr(34))
URL 是一个表单,参数是表单的一些字段,因此用户无需键入它们。
通常,用户填写表格并重定向到“谢谢”页面。
我的问题:下次用户单击菜单并打开 URL\表单时,根据当前应用程序阶段,表单中应该有不同的字段值,但在某些计算机\用户\浏览器上,第一个 URL 被缓存,之后,所有表单都填充了初始字段,因此用户需要手动编辑它们(如果他注意到问题),否则我会得到包含不准确信息的表单结果 - 新用户用先前的错误注释字段值。
我的表单页面现在以 -
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
直到今天,它以以下所有选项开始 -
<?php
//disable all browser caching MUST BE FIRST LINES WITH NO PRECEEDING SPACES ETC
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
文件“myAppTemp.url”已更新,但浏览器打开旧链接。
In my application (*) I sometimes needs to open (in the default user browser) a URL with some parameters.
On some computers, I had cache problem, even if I send different parameters, the browser opened the page with the old parameters.
I tried to add time-stamp as the first parameter:
- e.g.: http://www.mySite.com/myPage.php?pXXX=XXX&p1=param1&p2=param2&p3=param3
- where XXX = Now.ToString("ssmmHHddMMyy")
but still, on some computers it did not solve the problem.
I wonder if using friendly URLs will help avoiding the cache problem for all users, all browsers, all default settings etc.
[ My source for using friendly URLs:
- http://techie-buzz.com/how-to/create-seo-friendly-urls-using-mod-rewrite-and-php-part-1.html
- http://techie-buzz.com/tips-and-tricks/create-seo-friendly-urls-with-mod-rewrite-and-php-part-ii.html
]
Are you aware of any dis-advantages in using this method of passing parameters?
Thanks,
Atara.
(*) My application is an exe file (VB .Net)
One of the menu options of the application is opening the URL, using the user default browser:
'-- Create temporary *.url file and open it
Try
Dim line1 As String = "[InternetShortcut]"
Dim line2 As String = "URL=" & sUrl
Dim dst As String = GetSystemPathTemp() & "myAppTemp.url"
Dim sw As New System.IO.StreamWriter(dst, False)
sw.WriteLine(line1)
sw.WriteLine(line2)
sw.Close()
System.Diagnostics.Process.Start(Chr(34) & dst & Chr(34))
The URL is a form, the parameters are some of the fields of the form, so that the user wont have to type them.
Usually the user fills-in the form and re-directed to a "Thank you" page.
My problem: The next time the user clicks the menu, and opens the URL\form, there should be different field values in the form, according to the current application stage, BUT on some computers\users\browsers the first URL is cached, and after that, all forms are filled with the initial fields, so the user needs to manually edit them (If he noticed the problem), otherwise I get the form results with non-accurate information - the new user notes with the previous-wrong field-values.
My form page now starts with -
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
Until today, it started with all the following options -
<?php
//disable all browser caching MUST BE FIRST LINES WITH NO PRECEEDING SPACES ETC
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
The file "myAppTemp.url" is updated, but the browser opens the older link.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决缓存问题的 URL 并不是正确的方法。 URL 应该代表访问内容的方法,仅此而已。
最终,您将永远无法完全解决客户端缓存问题,因为他们可以为所欲为。然而,有了一些有意义的标题,你就会没事的。
来自: http://php.net/manual/en/function.header.php
The URL to solve a cache problem is not the way to go. The URL should represent a method to access the content, and nothing more.
In the end, you will never be able to completely resolve the clients caching, as they can do whatever they want. However, with some sensical headers, you will be just fine.
From: http://php.net/manual/en/function.header.php
我认为您正在寻找错误的答案。如果查询字符串不同,客户端永远不会加载缓存的数据,但是如果内容(具有链接的页面)被缓存,那么您将再次请求相同的数据,即使您预计参数已更改。
如果您在页面加载时动态生成 url,这可能会出现问题。一旦用户离开该页面,然后返回,该页面上将具有相同的 url,因为该页面已被缓存。
编辑:
我认为您可以绕过 .url 文件的创建,因为 Windows 支持直接打开 http 链接,请阅读这篇文章: http://support.microsoft.com/kb/305703
这样您至少可以消除问题的一个错误源。
I think you are looking for the wrong answer. A client would never load cached data if the querystring is different, however if the content (the page that has the link) is cached, then you would request the same data once more, even if you expect the parameters to have changed.
This could be a problem if you on pageload generate urls dynamically. Once a user navigates away from that page, and then go back, it would have the same url on the page because THAT page was cached.
EDIT:
I think you could bypass the creation of the .url file, because windows support opening of http links directly, read this article: http://support.microsoft.com/kb/305703
That way you at least eliminate one error source for your problem.