Working with Sessions in Multi Tab Browsers - PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • salmankamkoriwala
    New Member
    • Mar 2008
    • 3

    Working with Sessions in Multi Tab Browsers - PHP

    Default Working with Sessions in Multi Tab Browsers - PHP
    Hi,

    I am working on the php project and been stuck on Managing Session in Multiple tabs.

    My Problem is ---

    When i open a page in firefox window i store the id of product in session[productid] and then manage all stuff related to that product with that session i.e. edit, delete, add subproduct, comment etc..

    But when i open another tab in same window for some other product then my previous session for the product 'session[productid]' is overwritten with this new product id. So all the stuffs that i do on the previous product is actually done on new product that i opened in new tab. this is because my session for product id is overwritten.

    This is a very serious issue as this might cause to lose of data or data corruption.

    Any Help will be greatly appreciated.

    Thanks,
    Salman
    Reply With Quote
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    ...... But when i open another tab in same window for some other product then my previous session for the product 'session[productid]' is overwritten with this new product id ......
    Welcome to The Scripts!

    When you write something in the $_SESSION['productid'] it stays there until you either unsert the variable, close the browser sesion or overwrite the variable, what else do you expect? You obviously overwrite it, as your posts says.

    Now, when you want to keep all these productid's in the $_SESSION array, you can make a sub-array of productid, so the first to come in is stored in
    Code:
    $_SESSION['productid'][0]
    and the second one in
    Code:
    $_SESSION['productid'][1]
    and so on.

    Ronald

    Comment

    • aktar
      New Member
      • Jul 2006
      • 105

      #3
      An alternative you may consider is cookies. But as is with most browsers, cookies must be enabled for this to work.

      Comment

      • salmankamkoriwala
        New Member
        • Mar 2008
        • 3

        #4
        Thanks for the quick reply. I really appreciate the response to my problem. Thanks buddy...[php]ob_start();
        if(version_comp are(phpversion( ),'4.3.0')>=0) {
        if(!ereg('^SESS[0-9]+$',$_REQUEST['SESSION_NAME'])) {
        $_REQUEST['SESSION_NAME']='SESS'.uniqid( "");
        }
        output_add_rewr ite_var('SESSIO N_NAME',$_REQUE ST['SESSION_NAME']);
        session_name($_ REQUEST['SESSION_NAME']);
        session_start() ;
        $SESS_VAR = "&".session_nam e().'='.session _id().'&SESSION _NAME='.session _name();
        }
        [/php]
        I have tried the above code to regenerate session name for each new tab but what happens is it actually regenerate the session name each time i refresh the page in same tab or go to some other link from the page and due to this my sessions are distroyed.

        Please guide me if i have coded something strange in this. I have put this code on the first line of my index.php file.

        Thanks,
        Salman
        Last edited by ronverdonk; Mar 31 '08, 08:36 AM. Reason: code tags!

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          Please enclose your posted code in [code] tags (See How to Ask a Question).

          This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

          Please use [code] tags in future.

          MODERATOR

          Comment

          • salmankamkoriwala
            New Member
            • Mar 2008
            • 3

            #6
            Sorry for the inconvinience made to you due to my question without the code tags.
            Next time I will take care of this things.

            Thanks,
            Salman

            Comment

            Working...