Results 1 to 2 of 2

Thread: [RESOLVED] Adding User_ID session variable upon login

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    790

    Resolved [RESOLVED] Adding User_ID session variable upon login

    After logging into my site, I need to have the User_ID from the mysql table be saved as another session variable so I can reference the user later.

    I added this to my page:

    <?php $_SESSION['User_ID'] = $row_Recordset1['User_ID'] ?>

    My first recordset is table1 (has member information in it).

    I then created a recordset from table2 (has the user_id and financial info there): recordset2 filters the field "User_ID" based on the session variable, "User_ID".

    I am then trying to insert information from that recordset, but nothing happens.

    When the user logs in, he is directed to the account page.

    I have that code typed in near the top of the php page.

    I tested it many times and I cant seem to get it to show the session.

    I added the session variable in the bindings panel. Of course, I named it "User_ID". I drag that onto my contents section of the account page.

    When I log in, no user id appear in its place.

    It's funny. If I do something like this:
    <?php $_SESSION['User_ID'] = '1' ?>

    ... and then reference the session variable onto my screen, the number '1' DOES appear.

    Leads me to believe that the user_id from recordset1 one is not registering properly.

    Thanks for the attention.

    Oh... does it matter that I had once used another session variable called MM_Username? I didn't think.. upon logging into the site, that session variable is created as I can use it later.

    I was going to add the user_id as a session variable so when users move to another account page that is based on another table it will filter by user_id and then display that info.

    Here is the top of my account page script that shows after logging in:
    Code:
    <?php if (!isset($_SESSION)) session_start(); ?>
    <?php require_once('Connections/connectDB.php'); ?>
    <?php
    //initialize the session
    if (!isset($_SESSION)) {
    session_start();
    }
    
    // ** Logout the current user. **
    $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
    if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
    $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
    }
    
    if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
    //to fully log out a visitor we need to clear the session varialbles
    $_SESSION['MM_Username'] = NULL;
    $_SESSION['MM_UserGroup'] = NULL;
    $_SESSION['PrevUrl'] = NULL;
    unset($_SESSION['MM_Username']);
    unset($_SESSION['MM_UserGroup']);
    unset($_SESSION['PrevUrl']);
    
    $logoutGoTo = "index.php";
    if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
    }
    }
    ?>
    <?php $_SESSION['User_ID'] = $row_Recordset1['User_ID'] ?>
    Why won't the session variable "User_ID" be loaded once the account page is viewed after logon?

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    790

    Re: Adding User_ID session variable upon login

    I figured it out.

    Placement problem.

Posting Permissions

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



Click Here to Expand Forum to Full Width