Jump to content

Sessions


supermerc

Recommended Posts

Hi I'm trying to welcome my members so when they come in to my page it will say welcome, Your Name, You are logged in as Username.

 

<?
session_start();
require("config.php");
require("functions.php");
echo '<p>Welcome, '.$_SESSION['s_name'].',</p>';
echo '<p>You are logged in as '.$_SESSION['s_username'].'.</p>';
?> 

 

But It doesnt show the username, for some reason it shows the database username...

 

Here is my login script, incase you need it to help:

 

<?php
      session_start();
      require("config.php");
      require("functions.php");
       
      //echo some styles to spice it up...
      echo "
      <style>
      body
      {
      background: #ffffff;
      font-family: Verdana, Arial;
      font-weight: bold;
      font-size: 9px;
      color: #000000;
      }
      .register_box
      {
      border: 1px solid #323232;
      background: #202020;
      font-family: Verdana, Arial;
      font-weight: bold;
      font-size: 9px;
      color: #FFFFFF;
      }
      </style>
      ";
       
      if(!isset($_SESSION['logged_in']))
      {
      if(!isset($_POST['check_login']))
      {
      echo "
      <form action='login.php' method='post'>
      Username: <input type='text' name='username' />
      <br />
      Password: <input type='password' name='password' />
      <br />
      <input type='submit' name='check_login' value='Login' />
      </form>
      ";
      }
      elseif(isset($_POST['check_login']))
      {
      $username = mysql_real_escape_string($_POST['username']);
      $password = md5($_POST['password']);
       if(empty($_POST['password']) || empty($username))
      {
      echo "You left a field blank!";
      }
      else
      {
      $check_login = mysql_query("SELECT username, password, id FROM user_system WHERE username = '$username' AND password = '$password' LIMIT 1");
      if(mysql_num_rows($check_login) > 0)
      {
      $_SESSION['logged_in'] = 1;
      $_SESSION['username'] = $username;
      echo "You have been successfully logged in!";
      }
      else
      {
      echo "Sorry. Wrong password, or user does not exist.";
      }
      }
      }
      }
      else
      {
      echo "You are already logged in.";
      }
      ?> 

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/41529-sessions/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.