A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yeardetect current tab - page 1
User InfoPosts
detect current tab#1
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.

posted date: 2008-12-28 17:26:00


Re: detect current tab#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-28 17:26:01


Re: detect current tab#3
Never deny a user from basic usability.

posted date: 2008-12-28 17:28:00


Re: detect current tab#4
Two issues I see:You're denying the user the ability to open the webpage in multiple tabs -- something that is nearly a requirement for web-applications.This issue brings up a design problem.You may want to consider changing your $_SESSION variable to a singleton, and not allow it to be overwritten by multiple page views.

posted date: 2008-12-28 17:48:00


Re: detect current tab#5
He already stated that he wants a quick and dirty temporary solution. Anyhow I can't understand how the singleton pattern helps in this case. Singleton $_Session? There is no application in php so there can't be a singleton either. Every object dies when response ends.

posted date: 2008-12-28 17:52:00


Re: detect current tab#6
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 ( $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)

posted date: 2008-12-28 17:58:00


Re: detect current tab#7
I'd recommend avoiding the use of $_SESSION to store search filters, and instead encode them in the search query string (i.e. /search.php?filter1=val&filter2=val, etc). That way, each window has a unique URL and avoids clobbering another window.

posted date: 2008-12-28 18:19:00


Re: detect current tab#8
I agree with arjun's answer but if you must use sessions for this then you could create an array containing the information for each search inside the PHP session.e.g. every time the form is submitted$key = md5(rand(time(), 1));if (!isset($_SESSION['search_filters'])) { $_SESSION['search_filters'] = array();}$filters = & $_SESSION['search_filters'][$key];//store stuff$filters = array( 'something' => true );then you can construct a url like results.php?key=$key and then retrieve the data by$filters = &$_SESSION['search_filters'][$_GET['key']];if (!isset($filters)) die('cannot find search');//do stuff with dataprint_r($filters);A problem you will have is that the session will get bigger and bigger as the user performs more searches, again I would go with arjun's answer, but I thought I would add another possible approach

posted date: 2008-12-29 02:33:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.