Ok on my site's pages I want to include a small bar that says: Hey <username> when user is logged in or display a login/password text field if the user is not logged in.
on my html pages this is what i have done:
<?
include ('login.htm')
?>
HTML CODE
/// Now where I want the bar thing...I have ran a function
<?
check ();
?>
And login.htm file:
<?
session_start();
session_register("username");
session_register("password"); // register username and password as session variables.
function check ()
{
global $username,$password,$valid_user,$submitlogin;
require ('config.php');
if (!empty($submitlogin))
{
mysql_connect ($db_host,$db_user,$db_pass) or die ("Unable to connect to database");
mysql_select_db ($db_name);
$result = mysql_query ("SELECT * FROM members WHERE user = '$username'");
$row = mysql_fetch_array($result);
$numrows = mysql_num_rows($result);
if ($numrows !=0 & $password==$row[pass]) {
$valid_user=1;}
else {
$valid_user = 0;
echo('<script language="javascript">javascript:alert("Invalid username/password")</script>');}
}
if ((!isset($username)))
{
session_unset(); // Unset session variables.
session_destroy(); // End Session we created earlier.
dologin();
}
else {
echo '<p align="right" class"small">Hey ';
echo $_SESSION['username'];
echo ' you are logged in. <a href = "account.htm">my accont</a> | <a href ="logout.htm"> logout</a></p>';
}
}
function dologin () {
echo('
<p class="small" align= "right">
<form method="POST" action="">
Username<input type="text" name="username" size="10" class="box" onMouseOver="this.focus()"> Password <input type="password" name="password" size="10" class="box" onMouseOver="this.focus()">
<input type="submit" value="go" name="submitlogin" class="box2">
</form>
</p>
');
}
?>
THE PROBLEM: This works fine when I try to login in one window.
But when I open a new window and load the html page, it asks me to login 🙁 And some times it doesn't work even in one window. I have peeled enough hair over this code...so PLZ HELP!! lol.
G