Detect current tab

Is it possible to tell if a page opens in two different browsers?

I created a small app that stores some data in $ _SESSION and the problem is that when multiple tabs are opened, the session vars are overwritten (search filters in the search form) and so the tabs can show the same results for obviously different searches.

The main browser used for this app is IE, so it took a while to fix this issue and the app got ... bigger and harder to change.

Until I commit all links to this search, I would like to do a "quick and dirty fix" and prevent two tabs from opening with the same page from opening, or at least displaying a warning ..

edit: @arjun: yes I know, but I need to restore the search filters when the user returns to the search page :) so SESSION is the way to go for it. Also, filters are sent by AJAX and it is difficult to debug when you have many filters (GET is limited in size, so I use POST)

@tomhaigh: thanks..but this is what i'm trying to do right now but it will take a while because this 'thing' tab affects the whole application and i need to change filters in all modules ... i was looking for something- that's quick and dirty. Council. I don't want to use time () and rand () as these functions can (and eventually) generate duplicate numbers. In a new "rewrite", I use microtime from PHP and Date.getTime () in JS and combine the 2 to generate a truly unique ID. Also, I wrote a function to parse SESSION from time to time and clear stored filters older than 2 hours so it doesn't get too big.

@Gortok: I know .. but was designed with IE6 in mind and most users (something like 90%) are still using IE6 when entering this app ... so I never saw the need to look at multiple open tabs.

0


source to share


5 answers


Well, this is a design issue that needs to be fixed as soon as possible. Fast and discreet is a dirty way to handle this, but this would store the client's IP in $ _SESSION ( $ip=$_SERVER['REMOTE_ADDR'];

). Then check and don't create a new session or show a warning if multiple requests are made from this address. This will cause problems for visitors who are on the local network using the same IP address. I can’t think anything else .. fast (or dirty)



+1


source


I would recommend avoiding using $ _SESSION to store search filters and instead encode them in the search string (e.g. / search.php? Filter1 = val & filter2 = val, etc.). This way, each window has a unique URL and lets you hide another window.



+6


source


I agree with arjun's answer, but if you must use sessions to do this, then you can create an array containing information for each search in a PHP session.

eg. 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 can you create a url like result.php? key = $ key and then get the data

$filters = &$_SESSION['search_filters'][$_GET['key']];
if (!isset($filters)) die('cannot find search');

//do stuff with data
print_r($filters);

      

The problem you will run into is that the session will get larger and larger as the user makes more requests, again I would go with arjun's answer but I thought I would add another possible approach

+1


source


Never prevent a user from using normal convenience.

0


source


Two questions I see:

  • You prevent the user from opening a web page in multiple tabs - something almost necessary for web applications.
  • This issue is causing design issues.

You might want to change your variable $_SESSION

to singleton and not allow it to be overwritten by multiple view pages.

0


source







All Articles