Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 10 of 10
  1. #1
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    Hi! I'm 11 and im trying to make a website for kids my age. I'm trying to figure out how to greet the user by there username. anything i try, just shows up as: Welcome ! (dont forget the space)

    Here is my home page code (where i want it to show.) (index.php)

    Code:
    <?php
    session_start();
    
    include('class.login.php');
    include 'csstemplate.inc';
     
    $login = new Login();
    
    if($login->isLoggedIn())
     
    echo '
    <table border="0" align="center">
    
        <td><h1>Home</h1>
    
    SHOW "WELCOME USER" HERE!!!!!
    
    <br />
    
    <h1>ATTENTION!</h1><br>
    <p>
    We are going to update are Website theme! so you might see things messed up for a few days. <br>
    So please check back later for a more user friendly interface!
    </p>
    <br>This club is for kids who want to have fun! so have fun!
     
    <br><h3> Please Download my linux!</h3>
        
    <A href="http://susestudio.com/download/daccbf1569d3da67a4ea0d4f4046f9bd/Kd2mays_Linux.i686-11.9.0.iso">Version 11.9</A>
    
    <br>
    </table>
    </body>
    </html>
    
    ';
     
    else
    
      echo '
    <table border="0" align="center">
        <td><h1>Home</h1>
       
    <h2>
    Welcome to Yoshee08!</h2>
    <br />
    
    <h1>ATTENTION!</h1><br>
    <p>
    We are going to update are Website theme! so you might see things messed up for a few days. <br>
    So please check back later for a more user friendly interface!
    </p>
    <br>This club is for kids who want to have fun! so have fun!
     
    <br><h3> Please Download my linux!</h3>
        
    <A href="http://susestudio.com/download/daccbf1569d3da67a4ea0d4f4046f9bd/Kd2mays_Linux.i686-11.9.0.iso">Version 11.9</A>
    
    </table>
    </br>
     
    </body>
    </html>
    
    ';
    ?>
    Here is my Check Login Code! (class.login.php)

    Code:
    <?php
    
    class Login
    {
      private $_id;
      private $_username;
      private $_password;
      private $_passmd5;
    
      private $_errors;
      private $_access;
      private $_login;
      private $_token;
    
      public function __construct()
      {
        $this->_errors = array();
        $this->_login  = isset($_POST['login'])? 1 : 0;
        $this->_access = 0;
        $this->_token  = $_POST['token'];
    
        $this->_id      = 0;
        $this->_username = ($this->_login)? $this->filter($_POST['username']) : $_SESSION['username'];
        $this->_password = ($this->_login)? $this->filter($_POST['password']) : '';
        $this->_passmd5  = ($this->_login)? md5($this->_password) : $_SESSION['password'];
      }
    
      public function isLoggedIn()
      {
        ($this->_login)? $this->verifyPost() : $this->verifySession();
    
        return $this->_access;
      }
    
      public function filter($var)
      {
        return preg_replace('/[^a-zA-Z0-9]/','',$var);
      }
    
      public function verifyPost()
      {
        try
        {
          if(!$this->isTokenValid())
            throw new Exception('Invalid Form Submission');
    
          if(!$this->isDataValid())
            throw new Exception('Invalid Form Data');
    
          if(!$this->verifyDatabase())
            throw new Exception('Invalid Username/Password');
    
        $this->_access = 1;
        $this->registerSession();
        }
        catch(Exception $e)
        {
          $this->_errors[] = $e->getMessage();
        }
      }
    
      public function verifySession()
      {
        if($this->sessionExist() && $this->verifyDatabase())
          $this->_access = 1;
      }
    
      public function verifyDatabase()
      {
        //Database Connection Data
        mysql_connect("ipaddress", "database", "Pass") or die(mysql_error());
        mysql_select_db("database") or die(mysql_error());
    
        $data = mysql_query("SELECT ID FROM users WHERE username = '{$this->_username}' AND password = '{$this->_passmd5}'");
    
        if(mysql_num_rows($data))
          {
            list($this->_id) = @array_values(mysql_fetch_assoc($data));
            return true;
          }
        else
          { return false; }
      }
    
      public function isDataValid()
      {
        return (preg_match('/^[a-zA-Z0-9]{5,12}$/',$this->_username) && preg_match('/^[a-zA-Z0-9]{5,12}$/',$this->_password))? 1 : 0;
      }
    
      public function isTokenValid()
      {
        return (!isset($_SESSION['token']) || $this->_token != $_SESSION['token'])? 0 : 1;
      }
    
      public function registerSession()
      {
        $_SESSION['ID'] = $this->_id;
        $_SESSION['username'] = $this->_username;
        $_SESSION['password'] = $this->_passmd5;
      }
    
      public function sessionExist()
      {
        return (isset($_SESSION['username']) && isset($_SESSION['password']))? 1 : 0;
      }
    
      public function showErrors()
      {
        echo "<h3>Errors</h3>";
    
        foreach($this->_errors as $key=>$value)
          echo $value."<br>";
      }
    }
    
    ?>

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    So do you have a database all set-up, everything works ... you can log-in, etc.
    It's just saying Hello "name" that is the problem? Let us know if everything else
    is working and setup properly.


  4. #3
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    Yes, I have everything set up right, but all it shows if i put code in place of "
    SHOW "WELCOME USER" HERE!!!!!" It just shows "Welcome !.

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    echo '
    <table border="0" align="center">
    <td><h1>Home</h1>
    Welcome {$_SESSION['username']} !
    <br />


  6. #5
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    It does not work. it just shows "Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/content/19/8804119/html/index.php on line 15"

  7. #6
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    Repost it ... with the change that caused the error.
    Must be a double quote/single quote issue.


  8. #7
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    Here it is. also, I was wondering if there was a way i could have like a privet chat (like email, not a chat box.) so members can interact with each other.

    Code:
    <?php
    session_start();
     
    include('class.login.php');
    include 'csstemplate.inc';
     
    $login = new Login();
      
    if($login->isLoggedIn())
    
    echo '
    <table border="0" align="center">
    <td><h1>Home</h1>
    Welcome {$_SESSION['username']} !
    <br />
    
    <h1>ATTENTION!</h1><br>
    <p>
    We are going to update are Website theme! <br> so you might see things messed up for a few days. <br>
    So please check back later for a more user friendly interface!
    </p>
    <br>This club is for kids who want to have fun! so have fun!</td>
    </table>
    </body>
    </html>
    
    ';
     
    else
    
      echo '
    <table border="0" align="center">
    
    <h1>Home</h1>
    
    <h2>
    Welcome to Yoshee08!</h2>
    <br>
    
    <h1>ATTENTION!</h1><br>
    <p>
    We are going to update are Website theme! so you might see things messed up for a few days. <br>
    So please check back later for a more user friendly interface!
    </p>
    <br>This club is for kids who want to have fun! so have fun!
        
    <br>
    </table>
    </body>
    </html>
    
    ';
    ?>

  9. #8
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    138 times
    It's been a while, but it may be the echo ' doing it. You're using the same quote within username, so it stops and starts again. Been a while though, could be wrong.

    Since the only thing different between the two tables is the welcome line, I'd simplify the code a bit. (UNTESTED, incomplete code!!!) Been a while since I did PHP, so I know the code's wrong for the if/then/else.

    Doing it like this makes the code smaller, and less text / HTML formatting to correct later on (e.g. "We are going to update are Website theme" should be "We are going to update OUR website theme"). This way you only have to fix it in one location instead of two. Later on if you choose to program more difficult sites you'll find more efficient ways than this to re-use text and HTML.

    PHP Code:
    <?php
    session_start
    ();

    include(
    'class.login.php');
    include 
    'csstemplate.inc';

    $login = new Login();

    ?>

    <table border="0" align="center">
    <td><h1>Home</h1>
    <? if($login->isLoggedIn())
    then echo "Welcome {$_SESSION['username']} !"
    else echo "Welcome {$_SESSION['username']} "
    ?>
    <br />
    <h1>ATTENTION!</h1><br>
    <p>
    We are going to update are Website theme! <br> so you might see things messed up for a few days. <br>
    So please check back later for a more user friendly interface!
    </p>
    <br>This club is for kids who want to have fun! so have fun!</td>
    </table>
    </body>
    </html>
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  10. #9
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    THANKS MAN!!! That almost fully worked here is the code i ended up using!

    PHP Code:
    <?php
    session_start
    ();

    include(
    'class.login.php');
    include 
    'csstemplate.inc';

    $login = new Login();

    ?>

    <table border="0" align="center">
    <td><h1>Home</h1>
    <? if($login->isLoggedIn())
    echo 
    " Welcome {$_SESSION['username']} ! ";
    else
    echo 
    " Welcome {$_SESSION['username']} ";
    ?>
    <br />
    <h1>ATTENTION!</h1><br>
    <p>
    We are going to update are Website theme! <br> so you might see things messed up for a few days. <br>
    So please check back later for a more user friendly interface!
    </p>
    <br>This club is for kids who want to have fun! so have fun!</td>
    </table>
    </body>
    </html>
    Here , you can see
    <? if($login->isLoggedIn())
    echo " Welcome {$_SESSION['username']} ! ";
    else
    echo " Welcome {$_SESSION['username']} ";
    ?> You forgot to put the colen ( after the quote (") then i just got rid of the "then" and it worked! Thanks! That saved me!!

  11. #10
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    138 times
    FYI that's a semi colon, not a colon. Don't want to mix those up

    You should still fix the spelling error I noted above. Also, the else should be "Welcome to Yoshi08", or something other than the username. Otherwise there's no need for an if/then/else.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com


Remove Ads

Posting Permissions

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

Search tags for this page

code for php login with welcome greet

,

logged in greeting php

,

php greeting user on login

Click on a term to search for related topics.
All times are GMT -6. The time now is 12:57 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com