Hi there, thanks for replying. I hope this works for you. Not really sure what the end result should be.
index.php
PHP Code:
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<?php
echo "<p class='title'>example.com / Demo / User Log In</p>
<p class='lastedited'><a href='http://www.example.com'>Home</a> | <a href='http://www.example.com/demo'>Back to Demo</a> | <b>Last updated on March 29, 2011</b></p><br />";
echo "<br /><br /><br />";
echo "<div align='center' style='width: 300px; background-color: #FFF; border: 1px solid #0087D4; margin: 0px auto 0px auto; padding: 20px 0px 20px 0px; font-family: arial; font-size: 12px'>"."
<form action='login.php' method='POST'><br /><br />
Username: <input type='text' name='username' /><br />
Password: <input type='password' name='password' /><br />
<br />
<input type='submit' value='Log in'>
</form>";
?>
</body>
</html>
login.php
PHP Code:
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if ($username && $password)
{
$connect = mysql_connect("localhost","******","*****") or die ("Could not connect");
mysql_select_db("session") or die ("Could not find db");
$query = mysql_query("SELECT * FROM login WHERE username = '$username'");
$numrows = mysql_num_rows($query);
if ($numrows != 0)
{
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
// check to see if they match!
if ($username == $dbusername && $password == $dbpassword)
{
echo "You are now logged in! <a href='member.php'>Click here to enter members area.</a>";
$_SESSION['username']=$username;
}
else
echo "<div style='font-family: Verdana; font-size: 12px;'>"."Incorrect password!"."</div>";
}
else
die("<div style='font-family: Verdana; font-size: 12px;'>"."No such user in database!"."</div>");
}
else
die ("<div style='font-family: Verdana; font-size: 12px;'>"."Please enter username and password!"."</div>");
?>
member.php
PHP Code:
<?php
session_start();
if ($_SESSION['username'])
echo "<div style='font-family: Verdana; font-size: 12px; border: 1px solid #43A5EC; background: #F0F0F0; padding: 10px;'>"."Welcome, "."<b>".$_SESSION['username']."</b>"."<b>!</b>";
else
die("<div style='font-family: Verdana; font-size: 12px;>"."You must be logged in!"."</div>");
echo " | "."<a href='http://localhost/login/change.php'>Change password</a> | <a href='http://localhost/login/change.php'>Forgot password?</a> | <a href='logout.php'>Logout<a/>"."</div>";
?>
logout.php
PHP Code:
<?php
session_start();
session_destroy();
echo "<div style='font-family: Verdana; font-size: 12px; border: 1px solid #43A5EC; background: #F0F0F0; padding: 10px;'>"."You've been logged out. <a href='index.php'>Click here to return."."</div>";
?>