检测当前标签 [英] detect current tab
问题描述
是否有可能检测到页面是否在两个不同的浏览器中打开?
我已经构建了一个小应用程序,它将一些数据存储在$ _SESSION中,问题是当打开多个选项卡时,会话变量会被覆盖(搜索表单中的搜索过滤器),因此这些选项卡可能会显示相同的结果以显示不同的搜索结果。
这个应用程序使用的主要浏览器是IE浏览器,所以它需要一段时间来解决这个问题,应用程序越来越难以修改。
在我修复所有对此搜索的引用之前,我想要做一个快速和肮脏的修复,并拒绝在同一页面打开两个标签,或者最少显示警告.. @Gortok:我知道。 。但是它的设计考虑了IE6,大多数用户(如90%)在登录此应用程序时仍然使用IE6 ...所以我从来没有看到需要考虑多个打开的标签。 那么这是一个设计问题,应该尽快解决。尽管如此,处理这个问题的一个快速且绝对肮脏的方法是将客户端的IP地址存储在$ _SESSION中( Is it possible to detect if a page is opened in 2 different browsers? I have built an small app, that stores some data in $_SESSION, and the problem is that when multiple tabs gets opened, the session vars gets overwritten (search filters in a search form) and so the tabs may display the same results for apparently different searches. The main browser used for this app is IE, so it took a while to hit this problem and the app got ..larger and harder to modify. Until i fix all the references to this search, i would like to do a "quick & dirty fix" and deny opening two tabs with the same page,or at least display a warning.. edit:
@arjun: yes, i know, but i have to restore the search filters when the user return to the search page:) so $SESSION is the way to go for this. Also, the filters are sent down by AJAX and it gets hard to debug when you have lots of filters(GET is limited in size, so i use POST) @tomhaigh: thx..but this is what i'm trying to do right now, but this will take a while because this tab "thing" affects the whole app, and i have to change the filters in all modules... i was looking for something quick&dirty for now. Tip: i dont want to use time() and rand() as theese functions can (and eventually will) generate duplicate numbers. In the new "rewrite" i use microtime from PHP and Date.getTime() in JS and concatenate theese 2 to generate a truly unique id. Also, i wrote a function to parse the SESSION from time to time and cleanup stored filters older than 2 hours so it wont grow too big. @Gortok: i know..but is was designed with IE6 in mind and most of the users (something like 90%) still use IE6 while logging into this app... so i never saw the need to consider multiple open tabs. Well this is a design problem that should be fixed asap. A quick and -surely- dirty way to deal with this though would be to store the client's IP address in $_SESSION ( 这篇关于检测当前标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
编辑:
@arjun:是的,我知道,但是我必须在用户返回搜索时恢复搜索过滤器页面:)所以$ SESSION是这样做的方式。另外,过滤器通过AJAX发送,当你有很多过滤器时,调试变得困难(GET的大小有限,所以我使用POST)。
$ b $ p
$ ip = $ _ SERVER ['REMOTE_ADDR'];
)然后检查并且不创建新会话,或者如果从该地址发出多个请求,则显示警告。这会对通过LAN共享相同IP地址的访问者造成问题。我想不出更多......快速(或肮脏)$ip=$_SERVER['REMOTE_ADDR'];
) Then check and not create a new session or display a warning if multiple requests are made from this address. This would cause problems for visitors that are over a LAN that share the same IP address. I can't think anything more .. quick ( or dirty)