Need some help with login script (logged page comes late)
Posted: Tue Apr 14, 2009 8:01 am
Hi guys. I'm going to lose my virginity on this forum (this is my first time here) so be gentle, please ^.^
I have this issue with a site I work on. So I have this
<div ID="whatever"> <?php include "login.php" ?> </div>
in a page and everything seems to work normal. If I am logged in, there's a "log out" link, and if I am not logged in, there's this form to writing your UN/PW in. Everything is fine, but after I write my UN/PW and press "Sign in" it shows the form as nothing has happened. If I move to another page on the site it changes to "sign out". So basicly it works, but it doesn't change when it have to change. Can you help me out? What do I have to change (if it's something simple) to make it show "Log out" after I click on the "Sign in" button?
Here's the "login.php" code:
I have this issue with a site I work on. So I have this
<div ID="whatever"> <?php include "login.php" ?> </div>
in a page and everything seems to work normal. If I am logged in, there's a "log out" link, and if I am not logged in, there's this form to writing your UN/PW in. Everything is fine, but after I write my UN/PW and press "Sign in" it shows the form as nothing has happened. If I move to another page on the site it changes to "sign out". So basicly it works, but it doesn't change when it have to change. Can you help me out? What do I have to change (if it's something simple) to make it show "Log out" after I click on the "Sign in" button?
Here's the "login.php" code:
Code: Select all
<?php
include ("../../connect.php");
if (!$_SESSION['user'])
{
?>
<img src="images/userlogin.jpg" alt="Sign in" />
<form method="post" action="aboutus.php">
<table border="0">
<tr><td><p class="caption">Name:</p></td></tr>
<tr><td><input name="user" type="text" /></td></tr>
<tr><td><p class="caption">Password:</p> </td></tr>
<tr><td><input name="pass" type="password" /></td></tr>
<tr><td style="text-align: right;"><input type="submit" name="Submit" value="Sign in" /></td></tr>
</table>
</form>
<p>Or <a href="register.php">Register</a>.</p>
<br />
<?php
if ($_POST['Submit'] == 'Sign in')
{
if ($_POST["user"] == NULL)
{
echo ("<p>Empty Name field.</p>");
exit();
}
else
{
if ($_POST["pass"] == NULL)
{
echo ("<p>Empty Password field.</p>");
exit();
}
}
$username = mysql_real_escape_string($_POST['user']);
$password = md5($_POST['pass']);
$sql = "SELECT * FROM users WHERE
username = '$username' AND
password = '$password'";
$result = mysql_query($sql) or die (mysql_error());
$num = mysql_num_rows($result);
if ($num == 0)
{
echo ("<p>Invalid Name/Password</p>");
}
else
{
$_SESSION['user'] = $username;
header("Location: aboutus.php");
}
}
}
else
{
?>
<a href="logout.php">Sign out</a>
<?php
}
?>