アカウントにログインするたびに、[ログアウト] タブが表示されるはずですが、コードに条件がありますが、[ログインと登録] タブが引き続き表示されます。誰か助けてください。どうもありがとう。:)
<?php
session_start();
if(isset($_SESSION['username']) && isset($_SESSION['password'])){
$username=$_SESSION['username'];
$password=$_SESSION['password'];
}
?>
<div class="navigation">
<ul>
<li><a href="Home.php">Home</a></li>
<li><a href= "GALLERY.php">Gallery</a></li>
<li><a href="contact.php">Contact Us</a></li>
</ul>
<ul>
<?php
if(isset($_SESSION['username'])&& isset($_SESSION['password'])){?>
<li><a href="?page=LogOut">Log Out</a></li>
<?php } else { ?>
<li><a href="?page=index2">Register</a></li>
<li><a href="?page=index">Log In</a></li>
<?php } ?>
</ul>
</div>
私のログイン用の別のクラス。
<html>
<?php
//Start session
session_start();
//Unset the variables stored in session
if(isset($_POST['username'])&& isset($_POST['password'])){
$username=$_POST['username'];
$password=$_POST['password'];
$con = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db('store',$con);
$sql = "SELECT *FROM `members` WHERE username='%s' AND password='%s'";
$sql = sprintf($sql,$username,$password);
$result=mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_assoc($result);
if(count($row)<=1){
echo "Incorrect username or Password!".count($row);
}else{
$_SESSION['memID']=$row['memID'];
$_SESSION['fname']=$row['fname'];
$_SESSION['lname']=$row['lname'];
$_SESSION['gender']=$row['gender'];
$_SESSION'username']=$row['username'];
$_SESSION['password']=$row['password'];
header("Location:Home.php");
}
mysql_close($con);
}
?>
<body>
<form name="loginform" action="login_exec.php" method="post">
<div id="body"><table width="309" border="0" align="center" cellpadding="2" cellspacing="5">
<tr>
<td colspan="2">
<!--the code bellow is used to display the message of the input validation-->
<?php
if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
echo '<ul class="err">';
foreach($_SESSION['ERRMSG_ARR'] as $msg) {
echo '<li>',$msg,'</li>';
}
echo '</ul>';
unset($_SESSION['ERRMSG_ARR']);
}
?>
</td>
</tr>
<tr>
<td width="116"><div align="right">Username</div></td>
<td width="177"><input name="username" type="text" /></td>
</tr>
<tr>
<td><div align="right">Password</div></td>
<td><input type="password" class="input" name="password" /></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input name="" type="submit" value="login" /></td>
</tr>
<tr>
<td><div align="left"></div></td>
<td><a href="index2.php">Register</a></td>
</tr>
</table>
</div>
</form>