Hey guys I am back to ask some more questions. My header file is set to display the login is the $_SESSION['user'] is not present or display just the logo if it is present. The problem I am comming across is that the code dosent work unless I logon twice.
Try it for yourself go to http://24.208.244.240/vlogs/header.php
and login with guest as the user and password. I have tried diffrent header("Cache-control:") types and none seem to help.
Here is the login.php that starts the session:
----CODE----
<?PHP
session_start();
header("Cache-control: private"); //IE 6 Fix
$user = $POST['username'];
$pass1 = md5($POST['password']);
$pass = substr($pass1, 0, 10);
//set the database connection variables
$dbHost = "localhost";
$dbUser = "web_admin";
$dbPass = "trin1784";
$dbDatabase = "vlogs";
//connet to the database
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
$result=mysql_query("select * from users where user_name= '$user' AND user_password= '$pass'", $db);
//check that at least one row was returned
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0){
while($row = mysql_fetch_array($result)){
//start the session and register a variable
$SESSION['user'] = $POST['username'];
//successful login code will go here...
echo '<CENTER>Welcome '; echo $_SESSION['user']; echo '</CENTER>';
echo '<META HTTP-EQUIV="refresh" CONTENT="10; URL=http://24.208.244.240/vlogs/header.php">';
//we will redirect the user to another page where we will make sure they're logged in
}
}
else {
//if nothing is returned by the query, unsuccessful login code goes here...
echo 'Incorrect login name or password. Please try again.';
}
?>
----/CODE----
And here is the header.php file:
----CODE----
<?
session_start();
header("Cache-control: private"); //IE 6 Fix
?>
<HTML>
<BODY>
<CENTER>
<TABLE>
<TR>
<TD>
<IMG SRC="splashheader.gif">
</TD>
<?
if(isset($_SESSION['user'])) {
echo "<TD ALIGN=\"right\">";
echo $_SESSION['user'];
echo " Logged In";
echo "</TD>";
echo "</TABLE>
</CENTER>
<BR><BR>
</BODY>";}
else{
echo "<TD ALIGN=\"right\">
<form method=\"POST\" action=\"login.php\">
Username: <input type=\"text\" name=\"username\" size=\"20\"><BR>
Password: <input type=\"password\" name=\"password\" size=\"20\"><BR>
<input type=\"submit\" value=\"Submit\" name=\"login\">
</form>
</TD>
</TR>
</TABLE>
</CENTER>
<BR><BR>
</BODY>";}
?>
----/CODE----
Any suggestions?