View Full Version : Tabs Cookies
bluewalrus
01-14-2010, 01:05 AM
Is there a way to initiate or differentiate between cookies per tab in the same browser?
For example
Tab one has:
example.com/page1.php?value=1
which has:
<?php
$write_it = $_GET['value'];
if (isset($write_it)) {
setcookie("Multiple_Tabs", $write_it, time()+3600);
?>
and then 2 additional tabs with the same address are opened in a users browser; does anyone know if there is (a)/are browser(s) that feature this, or how this could be accomplished without changing the content or name of the cookie? Thanks.
Or is there a way on creating the cookie to have it know which tab it came from?
bluewalrus
01-14-2010, 11:38 PM
The cookie would be set already if you were in the other tab though.
I don't understand - don't you want to see in all three tabs if the cookie is already set so you don't overwrite it? You would do:
if(!isset($_COOKIE)){
//set
}
bluewalrus
01-15-2010, 07:11 AM
I mean a) is there already a browser out there that supports this, b) if not which is where i think we're leaning towards how would i code it.
On the initial load of the page the first cookie is written, in tab two and etc. i want the same cookie written but to be able to differentiated on the server side (if that is the corrrect usage here, not quite sure).
if(!isset($_COOKIE['Multiple_tabs'])){
//this cookie was created in tab one
}
djr33
01-15-2010, 06:40 PM
There is no way to track this that I know of.
1) Tabs are in no way special. They are different windows that happen to be "tabs" in the GUI. <a href=... target="_blank"> will open in a new tab or a new window depending on user preference.
2) Because of that, you are then looking at tracking windows. How would you even start with this? What if the user opens a link from one page in a new window, or closes one of the windows.
3) If you knew the exact order of page visits it would be somewhat possible (based on request order, time, etc), but what if the user just hits the back button and refreshes?
Sessions (and cookies) are browser wide in all cases that I know of. If you close a certain window the session may be reset, but only if that is the last window with that site open.
You could track things with get variables if the user did not try to get around it-- just give them successive values in the url, so that each page has its own tracking number. With that, this would be vaguely possible, but not reliable.
There is one way to get around this, though. PHP is serverside and has no access to anything like this. But Javascript does. You can use Javascript to track windows (name them, coordinate their URLs, etc), and if you can use Javascript instead of PHP it might be possible to do some of what you want.
The more complex version of that might actually work very well for your purposes, but it would still require Javascript and I'm not sure how reliable it would be.
Javascript can access window properties. It can also store cookies. PHP can then access cookies.
So, if you can find a way to organize things correctly, you can have Javascript set a cookie on page load (on page focus??), and then PHP can respond based on that.
Alternatively, you could use Ajax to make it less complex (aside from the Ajax itself). Load the same page with PHP each time and have Javascript request certain elements of the page dynamically, based on the window name.
And as for the difference between a tab and a window, I don't believe there is any way at all to determine that, regardless of browser.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.