This is weird. I got things to work in IE, kind of. Upon logging in, I get a correct welcome message, "Hi [username]!". But then as soon as I visit another page (with the same header) I get "Hi !".
How do I read the information set in the session in order to call upon the actual username for every page? It seems as though right now things work fine only because upon logging in for the first time, the $username is being grabbed by the form entry. As soon as the form is no longer filled out, $username is no longer posted and therefore is lost, even though the session is still registered.
How do I fix this?
PHP Code:
$username = addslashes($_POST['username']);
$salt = "stophacking";
$password = md5($_POST['password']);
//$password = md5($salt.trim($_POST['password']));
if(session_is_registered('username')){
print '<table cellpadding="0" cellspacing="3" border="0">
<tr>
<td>Welcome <b>'.$username.'</b>!</td>
</tr>
</table>
';
} else {
$query = mysql_query("SELECT * FROM kokonut_members WHERE username='$username' AND password='$password'");
//$set = mysql_fetch_array($query);
if (mysql_num_rows($query)){
while($row = mysql_fetch_array($query)){
print '<table cellpadding="0" cellspacing="3" border="0">
<tr>
<td>Hi <b>'.$username.'</b>!</td>
</tr>
</table>
';
session_register('username');
}
} else {
print'
<form action="'.$PHP_SELF.'" method="post" name="submit">
<table cellpadding="0" cellspacing="3" border="0">
<tr>
<td><img src="images/username.gif" width="36" height="15" alt="" border="0" /></td>
<td><input type="text" name="username"></td>
<td><img src="images/password.gif" width="35" height="15" alt="" border="0" /></td>
<td><input type="password" name="password"></td>
<td><input type="image" style="padding-left:7px;" name="submit" src="images/login.gif" width="46" height="19"></td>
</tr>
</table>
</form>
';
}
}
Thanks!
Oh yes, and things seem not to work in Firefox even though I've cleared my cache and cookies about a thousand times. Is it my machine or are things really different in Firefox and should be coded differently?