Results 1 to 7 of 7

Thread: Tabs Cookies

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default Tabs Cookies

    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 Code:
    <?php
    $write_it 
    $_GET['value'];
    if (isset(
    $write_it)) {
    setcookie("Multiple_Tabs"$write_ittime()+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?
    Last edited by bluewalrus; 01-14-2010 at 05:04 PM.
    Corrections to my coding/thoughts welcome.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    PHP Code:
    if(isset($_COOKIE[])) 
    Jeremy | jfein.net

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    The cookie would be set already if you were in the other tab though.
    Corrections to my coding/thoughts welcome.

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    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:
    PHP Code:
    if(!isset($_COOKIE)){
    //set

    Jeremy | jfein.net

  5. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    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
    }
    Corrections to my coding/thoughts welcome.

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Yes, it is.
    Jeremy | jfein.net

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. The Following User Says Thank You to djr33 For This Useful Post:

    bluewalrus (01-16-2010)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •