How to share a variable between browser sessions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ikke

    #1

    How to share a variable between browser sessions

    I have to share a variable between browser sessions.
    One session for example changes the variable, the other sessions must
    see the changes (get the new value instead of the original value)
    it's not allowed to save the value in a database or to save it into a
    file. It must be a kind of global server variable, changeable by every
    session.

    tia
  • tintub@gmail.com

    #2
    Re: How to share a variable between browser sessions

    You could use an environment variable ($_ENV['foobar'])


    Ikke wrote:[color=blue]
    > I have to share a variable between browser sessions.
    > One session for example changes the variable, the other sessions must[/color]
    [color=blue]
    > see the changes (get the new value instead of the original value)
    > it's not allowed to save the value in a database or to save it into a[/color]
    [color=blue]
    > file. It must be a kind of global server variable, changeable by[/color]
    every[color=blue]
    > session.
    >
    > tia[/color]

    Comment

    • Chris Hope

      #3
      Re: How to share a variable between browser sessions

      tintub@gmail.co m wrote:
      [color=blue]
      > Ikke wrote:[color=green]
      >> I have to share a variable between browser sessions.
      >> One session for example changes the variable, the other sessions must
      >> see the changes (get the new value instead of the original value)
      >> it's not allowed to save the value in a database or to save it into a
      >> file. It must be a kind of global server variable, changeable by
      >> every session.[/color][/color]

      There are shared memory functions in PHP which may be able to accomplish
      what you are after: http://www.php.net/manual/en/ref.sem.php

      But other than that (if the above functions do not work) you can't do
      this without saving it into some sort of state file or database table.
      Is there any reason you don't want to do this? The problem with non
      persistant data that is only stored in memory is that if the web
      service or server is restarted then you're going to lose whatever the
      current value is.
      [color=blue]
      > You could use an environment variable ($_ENV['foobar'])[/color]

      That wouldn't hold from page to page. Whatever you set in $_ENV will
      only last for the duration that the page is parsed.

      --
      Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

      Comment

      • Deniz Adrian

        #4
        Re: How to share a variable between browser sessions

        hi tia,

        if i got you right, you want to write data from session into another.
        The gap there is you will have to know the session-id from each session.
        if you know them, you can accomplish the task with the following code:

        <?php

        // SESSION-ID of the session to write in is in $newSessId;

        // Save data from current Session
        session_write_c lose();

        $oldSessId= session_id($new SessId);

        // Change to new Session
        session_start() ;

        // Delete/Alter data into Session
        unset($_SESSION['unsetvar']);
        $_SESSION['altervar']="newvalue";

        // Save changes into Session
        session_write_c lose();

        // Switch back to previous session
        session_id($old SessId);
        session_start() ;

        ?>

        best regards
        deniz adrian


        Ikke wrote:[color=blue]
        > I have to share a variable between browser sessions.
        > One session for example changes the variable, the other sessions must
        > see the changes (get the new value instead of the original value)
        > it's not allowed to save the value in a database or to save it into a
        > file. It must be a kind of global server variable, changeable by every
        > session.
        >
        > tia[/color]

        Comment

        • Yevgen Varavva

          #5
          Re: How to share a variable between browser sessions

          What about cookies?

          "Ikke" <ikke_mmv@hotma il.com> ???????/???????? ? ???????? ?????????:
          news:42127f06$0 $12085$a344fe98 @news.wanadoo.n l...[color=blue]
          >I have to share a variable between browser sessions.
          > One session for example changes the variable, the other sessions must see
          > the changes (get the new value instead of the original value)
          > it's not allowed to save the value in a database or to save it into a
          > file. It must be a kind of global server variable, changeable by every
          > session.
          >
          > tia[/color]


          --
          Happy PHP'ing,(c) Team Zend


          Comment

          • Ikke

            #6
            Re: How to share a variable between browser sessions

            thanks for your inputs.
            I've solved it with shared memory.
            shmop (http://www.php.net/manual/en/ref.shmop.php)

            greetings

            Comment

            Working...