handling multiple sessions??

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

    #1

    handling multiple sessions??

    How do u guys handle multiple sessions??
    i.e, opening different browser windows by running
    iexplore.exe or clicking IE icons and opening the application. My
    sessions are mixing up.
    what i mean is
    suppose i log in my site using username "test".
    At this time I set $_SESSION['name']="test".
    And I use $_SESSION['name'] inside my application to print the
    username.
    Now if I open another browser & log in with "another test" the session
    variable is overwritten.Ano ther session is not created.

    Do you store the session in database or pass the session_id via get or
    post.
  • steve

    #2
    Re: handling multiple sessions??

    "john" wrote:[color=blue]
    > How do u guys handle multiple sessions??
    > i.e, opening different browser windows by running
    > iexplore.exe or clicking IE icons and opening the application. My
    > sessions are mixing up.
    > what i mean is
    > suppose i log in my site using username "test".
    > At this time I set $_SESSION[’name’]="test".
    > And I use $_SESSION[’name’] inside my application to print
    > the
    > username.
    > Now if I open another browser & log in with "another test" the[/color]
    session[color=blue]
    > variable is overwritten.Ano ther session is not created.
    >
    > Do you store the session in database or pass the session_id via get[/color]
    or[color=blue]
    > post.[/color]

    John, that is by design. You cannot have multiple users logged in
    with the same session variable. When you open another browser, it
    should not allow login, but say "user is logged in", and allow
    logout. Once the user logs out, then the login boxes appear.

    --
    http://www.dbForumz.com/ This article was posted by author's request
    Articles individually checked for conformance to usenet standards
    Topic URL: http://www.dbForumz.com/PHP-handling...ict139652.html
    Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=467184

    Comment

    • R. Rajesh Jeba Anbiah

      #3
      Re: handling multiple sessions??

      mailtome2004200 32002@yahoo.com (john) wrote in message news:<4c900ea0. 0408140155.1a06 8ccb@posting.go ogle.com>...[color=blue]
      > How do u guys handle multiple sessions??
      > i.e, opening different browser windows by running
      > iexplore.exe or clicking IE icons and opening the application. My
      > sessions are mixing up.
      > what i mean is
      > suppose i log in my site using username "test".
      > At this time I set $_SESSION['name']="test".
      > And I use $_SESSION['name'] inside my application to print the
      > username.
      > Now if I open another browser & log in with "another test" the session
      > variable is overwritten.Ano ther session is not created.
      >
      > Do you store the session in database or pass the session_id via get or
      > post.[/color]

      IMO, this question has been asked so many times. You should have
      searched the archives
      <http://groups.google.c om/groups?threadm= abc4d8b8.031218 0003.4df5d9f5%4 0posting.google .com>

      --
      | Just another PHP saint |
      Email: rrjanbiah-at-Y!com

      Comment

      • Terence

        #4
        Re: handling multiple sessions??

        R. Rajesh Jeba Anbiah wrote:[color=blue]
        > mailtome2004200 32002@yahoo.com (john) wrote in message news:<4c900ea0. 0408140155.1a06 8ccb@posting.go ogle.com>...
        >[color=green]
        >>How do u guys handle multiple sessions??
        >>i.e, opening different browser windows by running
        >>iexplore.ex e or clicking IE icons and opening the application. My
        >>sessions are mixing up.
        >>what i mean is
        >>suppose i log in my site using username "test".
        >>At this time I set $_SESSION['name']="test".
        >>And I use $_SESSION['name'] inside my application to print the
        >>username.
        >>Now if I open another browser & log in with "another test" the session
        >>variable is overwritten.Ano ther session is not created.
        >>
        >>Do you store the session in database or pass the session_id via get or
        >>post.[/color]
        >[/color]
        It's all well and good to say the question has been asked lots, but it
        would be more useful to provide a link to an instance where it has been
        answered. When you can't put your finger on the problem (and associated
        jargon), it's very difficult to find something in google using general
        searches. Because you understand the problem, you take it for granted
        that it is easy to find the solution. Not so if you don't understand the
        problem. I wish people wouldn't tell other newbies to go Google when
        they are genuinely in need of help and are not just being lazy.


        For all the reasons you (original poster) mentioned, any web application
        is infact a multi-threaded (each page/script request is a thread)
        application which has to deal with the issue of "concurrenc y". This is
        not an issue of the technology (in this case, PHP) as much as code
        design. You have to design your application in such a way as to deal
        with multiple operations happening at unpredictable times in
        unpredictable order. PHP session management allows you to centralise
        where persistant name/value pairs are stored, but it doesn't solve your
        concurrency issues. These issues are broader than any given
        language/platform and are widely discussed in many programming forums.
        The issue generally revolves around [multi-channel, asynchronous] access
        to a central data store. This could be anything from session vars, to a
        file on the server, or to a database.

        Search google for issues relating to "programmin g for concurrency"
        topics in general. Once you get the concept, then common sense prevails.
        You begin to understand why using functions like flock() are relatively
        beneficial (be it somewhat flawed given the possible http service model
        of your web server).

        The fact that the issue actually occured to you is a good sign. I don't
        think you will have too many difficulties understanding the problem and
        how to deal with it. Many so-called web "developers " never even twig to
        race conditions and concurrency. Then they wonder why the get
        "unexpected " behaviour and/or corrupt data.

        I found an article which mentions that it is good to use the same
        database connection resource but that's all I could find that was PHP
        specific. Apparently, it is not all that easy to turn up really good
        articles in Google. This is all I could come up with in reasonable time.
        http://www.devshed.com/index2.php?op...ge=0&hide_js=1
        Maybe there is a good reason why people have to keep asking this
        question on forums ;) If you have more questions in your quest on this
        topic, don't be put off by people telling you to go google. Ask away.
        "There is no question `stupider' than the one everyone had but was too
        afraid to ask".



        Comment

        • Tony Marston

          #5
          Re: handling multiple sessions??

          Having different sessions with multiple browser instances can be done, but
          it requires some less-than-simple effort. To have a different session you
          must use a different session id.

          Option (a) - you can bypass cookies and pass the session id within every
          URL, but this presents a security risk as that session id is clearly visible
          to the outside world and can be hijacked.

          Option (b) - if you are using cookies (the preferred option) then the
          session id is linked with a session name, the default being PHPSESSID. The
          solution that I have found is to use a different session name for each
          session. This allows the single cookie maintained by the web browser to
          contain multiple session id's, each with their own session name.

          Step 1 is to override PHP's default session name. I use a .htaccess file
          with the following entry:

          php_value session.name fred

          Step 2 is to include a hidden field called "session_na me" in every screen.

          Step 3 is to execute the following code at the start of every script:

          global $session_name;
          if (isset($_REQUES T['session_name'])) {
          // use session name passed via $_GET or $_POST
          $session_name = $_REQUEST['session_name'];
          } // if

          Step 4 is to have the following code in your logon script:

          // get details from any previous session
          if (isset($session _name)) {
          // use existing session name
          } else {
          // assign new session name
          $session_name = getNewSession(' menu');
          } // if
          session_name($s ession_name);
          session_start() ;
          session_unset() ;
          initSession();

          This uses the following user-defined functions:

          function getNewSession ($prefix='fred' )
          // create a new session name using $prefix + a 1 digit number
          {
          // step through numbers 0-99
          for ($i = 0; $i <= 99; $i++) {
          $session_name = $prefix .$i;
          if (!array_key_exi sts($session_na me, $_COOKIE)) {
          break;
          } // if
          } // if
          return $session_name;
          } // getNewSession

          function initSession()
          // standard session initialisation
          {
          ....
          if (!isset($_SESSI ON)) {
          if (isset($session _name)) {
          session_name($s ession_name); // set the session name
          } // if
          session_start() ; // open/reopen session
          } // if
          ....
          } // initSession

          Note that this will allow a suffix of 0-99 on the end of the session name of
          "fred".

          Step 5 is to have the following code at the start of every script
          (immediately after the code identified in step 2):

          initSession();

          This has the following effect:

          The URL for the logon screen does not contain the parameter "session_na me",
          therefore the logon screen will always generate a new session name.

          The URL for every other screen will contain "session_na me", therefore it
          will continue to use the session with that name and the session id
          associated with that name.

          If within a browser window the user creates a copy of that browser window
          then the existing session name will also be copied, in which case the same
          session will be used by more than one browser instance. This can be remedied
          by pressing the "logout" URL which will invoke the login screen which in
          turn will generate a new session name and hence a new session id.

          As you can see it is not trivial, but it can be done.

          --
          Tony Marston

          This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL



          "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@r ediffmail.com> wrote in message
          news:abc4d8b8.0 408152159.20b82 11c@posting.goo gle.com...[color=blue]
          > mailtome2004200 32002@yahoo.com (john) wrote in message
          > news:<4c900ea0. 0408140155.1a06 8ccb@posting.go ogle.com>...[color=green]
          >> How do u guys handle multiple sessions??
          >> i.e, opening different browser windows by running
          >> iexplore.exe or clicking IE icons and opening the application. My
          >> sessions are mixing up.
          >> what i mean is
          >> suppose i log in my site using username "test".
          >> At this time I set $_SESSION['name']="test".
          >> And I use $_SESSION['name'] inside my application to print the
          >> username.
          >> Now if I open another browser & log in with "another test" the session
          >> variable is overwritten.Ano ther session is not created.
          >>
          >> Do you store the session in database or pass the session_id via get or
          >> post.[/color]
          >
          > IMO, this question has been asked so many times. You should have
          > searched the archives
          > <http://groups.google.c om/groups?threadm= abc4d8b8.031218 0003.4df5d9f5%4 0posting.google .com>
          >
          > --
          > | Just another PHP saint |
          > Email: rrjanbiah-at-Y!com[/color]


          Comment

          Working...