SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display: Welcome John Smith / Logout

    I have this php code after my first login page... But it doesn't display the user's username... Any ideas?

    PHP Code:
    <p>Welcome <? echo $_SESSION['txtUserId']; ?>/ <a href="index.php">Logout</a></p>

  2. #2
    SitePoint Guru brent5392's Avatar
    Join Date
    Dec 2005
    Location
    Australia
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it doesn't display the username is means the session was not set correctly.
    PHP | MySQL | (X)HTML | CSS

  3. #3
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I printed the session array and yep appears there is an issue... Maybe you could take a peak at my login page?

    Array
    (
    [session_started] => TRUE
    [db_is_logged_in] => 1
    [username] =>
    )
    This is my login page, maybe you can see what I'm doing wrong...

    PHP Code:
    <?php

    // we must never forget to start the session
    if(empty($_SESSION['session_started']))
        {
            
    session_cache_expire(120);
            
    session_start();
            
    $_SESSION['session_started'] = "TRUE";
        }

    function 
    scramble($value)
    {
        
    //scramble the value to store semi-encrypted in the database
        
    $scrambledValue "";
        for(
    $i 0$i strlen($value); $i++)
        {
            
    $charInAscii ord(substr($value,$i,1));
            
    $charInAscii = ((($charInAscii 3) + 120) * 2);
            
    $scrambledValue $scrambledValue $charInAscii "%";
        }
        
    $scrambledValue substr($scrambledValue,0,(strlen($scrambledValue) - 1));
        return 
    $scrambledValue;
    }

    function 
    unscramble($value)
    {
        
    //unscramble the semi encrypted database value
        
    $unscrambledValue "";
        
    $token strtok($value"%");

        while(
    $token !== false)
        {
            
    $char = ((($token 2) - 120) / 3);
            
    $unscrambledValue $unscrambledValue chr($char);
            
    $token strtok("%");
        }
        return 
    $unscrambledValue;
    }

    $errorMessage '';
    if (isset(
    $_POST['txtUserId']) && isset($_POST['txtPassword'])) {

        include 
    'library/config.php';
        include 
    'library/opendb.php';
        
        
    $userId   $_POST['txtUserId'];
        
    $password scramble($_POST['txtPassword']);
        
        
    // check if the user id and password combination exist in database
        
    $result mysql_query("SELECT * FROM tbladministrators WHERE username='$userId' && PASSWORD = '$password'") or die(mysql_error());
        
        if (
    mysql_num_rows($result) == 1) {
            
    // the user id and password match, 
            // set the session
            
    $_SESSION['db_is_logged_in'] = true;
            
            
    // after login we move to the main page
            
    header('Location: memberStatus.php');
            exit;
        } else {
            
    $errorMessage 'Sorry, wrong user id / password';
        }
        
        include 
    'library/closedb.php';
    }
    ?>
    <html>
    <head>
    <title>Club Suntory Administration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="cs_style.css" rel="stylesheet" type="text/css">
    </head>

    <body>
    <?php
    if ($errorMessage != '') {
    ?>
    <p align="center"><strong><font color="#990000"><?php echo $errorMessage?></font></strong></p>
    <?php
    }
    ?>
    <form action="" method="post" name="frmLogin" id="frmLogin">
     <table width="400" border="1" align="center" cellpadding="2" cellspacing="2">
      <tr>
       <td width="150">User Id</td>
       <td><input name="txtUserId" type="text" id="txtUserId"></td>
      </tr>
      <tr>
       <td width="150">Password</td>
       <td><input name="txtPassword" type="password" id="txtPassword"></td>
      </tr>
      <tr>
       <td width="150">&nbsp;</td>
       <td><input name="btnLogin" type="submit" id="btnLogin" value="Login"></td>
      </tr>
     </table>
    </form>
    </body>
    </html>

  4. #4
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $_SESSION['db_is_logged_in'] = true;
    $_SESSION['txtUserId'] = $userId;


Bookmarks

Posting Permissions

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