PHP design advice
<p>I've been working on a website, and currently at the stage of login/session handling.</p>

<p>I want to know what is a better design in your opinion. (this website will be available to the public, so it should be user-friendly too).</p>

<p>P.S. sorry if this is not the correct php 'conventions', I am used to c/c++ programming.</p>

<p>Design #1:</p>

<pre><code>define("LOGGED_IN", false);
define("USERNAME", "Guest");
define("PASSWORD", "");
define("PLAYER_ID", -1);

...

if (!LOGGED_IN) {
     header("Location: login.php");
} else {
   ...
}

...

if ({condition for successful login}) {
    define("LOGGED_IN", true);
    define("USERNAME", "AJ");
    define("PASSWORD", "nottellingu");
    define("PLAYER_ID", 1);
}

...

printf("Hi, %s. Have a nice day.", USERNAME);  
</code></pre>

<p>Design #2:</p>

<pre><code>class user {
    private $id;
    private $logged_in;
    private $username;
    private $password;

    public function __construct($id, $username, $password, $logged_in = false) {
        $this-&gt;id = $id;
        ... blablabla
    }

    public function get_id() {
        return $this-&gt;id;
    }

    ... blablabla (pretend i declared all needed functions)
}

...

if ({condition for successful login}) {
    $id = get_userid($_SESSION['USERNAME']]);
    $user = new user($id, $_SESSION['USERNAME'], $_SESSION['PASSWORD'], true);
}

...

printf("Hi, %s. Have a nice day.", $user-&gt;get_username());  
</code></pre>

<p>You can give me your designs aswell. </p>

<p>Thanks</p>
