re-setting session variables in PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sumdumgaitu@hotmail.com

    #1

    re-setting session variables in PHP

    I'm using the following code for a login page in PHP. Everything
    works OK until someone else logs in from the same browser. As best I
    can tell $mail, $password, and $user_id are not getting updated in the
    session.

    I tried doing

    session_start() ;
    session_destroy ();

    $_SESSION['email'] = $email;
    $_SESSION['password'] = $password;
    $_SESSION['user_id'] = $user_id;

    which seems to prevent email, password, and user_id from being set.

    I'm using 4.1.2, no changes to php.ini (register_globa ls = On)

    Any suggestions, help, or comments greatly appriciated.

    Thanks!

    Thomas


    =============== =============== =============== =============

    <?php

    $email = addslashes($_PO ST['f-email']);
    $password = addslashes($_PO ST['f-password']);

    // connect to database

    # query the database here - if $password and $mail match,
    # return $user_id

    if (!$user_id) {

    // login failure

    header('Locatio n: login_error.php ');

    } else {

    // login is good. start a session for this user

    session_start() ;

    $_SESSION['email'] = $email;
    $_SESSION['password'] = $password;
    $_SESSION['user_id'] = $user_id;

    // and send them on their way

    header('Locatio n: home.php');

    }

    ?>

  • Amir Khawaja

    #2
    Re: re-setting session variables in PHP

    sumdumgaitu@hot mail.com wrote:
    [color=blue]
    > I'm using the following code for a login page in PHP. Everything
    > works OK until someone else logs in from the same browser. As best I
    > can tell $mail, $password, and $user_id are not getting updated in the
    > session.
    >
    > I tried doing
    >
    > session_start() ;
    > session_destroy ();
    >
    > $_SESSION['email'] = $email;
    > $_SESSION['password'] = $password;
    > $_SESSION['user_id'] = $user_id;
    >
    > which seems to prevent email, password, and user_id from being set.
    >
    > I'm using 4.1.2, no changes to php.ini (register_globa ls = On)
    >
    > Any suggestions, help, or comments greatly appriciated.
    >
    > Thanks!
    >
    > Thomas
    >
    >
    > =============== =============== =============== =============
    >
    > <?php
    >
    > $email = addslashes($_PO ST['f-email']);
    > $password = addslashes($_PO ST['f-password']);
    >
    > // connect to database
    >
    > # query the database here - if $password and $mail match,
    > # return $user_id
    >
    > if (!$user_id) {
    >
    > // login failure
    >
    > header('Locatio n: login_error.php ');
    >
    > } else {
    >
    > // login is good. start a session for this user
    >
    > session_start() ;
    >
    > $_SESSION['email'] = $email;
    > $_SESSION['password'] = $password;
    > $_SESSION['user_id'] = $user_id;
    >
    > // and send them on their way
    >
    > header('Locatio n: home.php');
    >
    > }
    >
    > ?>
    >[/color]

    Thomas,

    It seems to me like you are hitting the same bug I encountered a while
    back on PHP 4.1.2. This is a documented bug and I would advise you to
    upgrade your PHP4 version to the latest one. Here is a link to the bug
    report:



    Amir.

    --
    Rules are written for those who lack the ability to truly reason, But for
    those who can, the rules become nothing more than guidelines, And live
    their lives governed not by rules but by reason.
    - James McGuigan

    Comment

    • RootShell

      #3
      Re: re-setting session variables in PHP


      <sumdumgaitu@ho tmail.com> escreveu na mensagem
      news:40d11bcc.2 347325@news.son ic.net...[color=blue]
      > I'm using the following code for a login page in PHP. Everything
      > works OK until someone else logs in from the same browser. As best I
      > can tell $mail, $password, and $user_id are not getting updated in the
      > session.
      >
      > I tried doing
      >
      > session_start() ;
      > session_destroy ();[/color]

      But you didnt do the two of them together right? You should *only* do the
      "session_destro y();" when you want the user to log out and not before trying
      to change "$_SESSION" fields.
      [color=blue]
      >
      > $_SESSION['email'] = $email;
      > $_SESSION['password'] = $password;
      > $_SESSION['user_id'] = $user_id;
      >[/color]



      Comment

      Working...