Forum Moderators: coopster
<?php
include 'functions.php';
if(isset($_POST['login_username']))
{
$username = $_POST['login_username'];
$password = $_POST['login_password'];
$sql = "SELECT * FROM users WHERE email = '".$username."' AND password = '".$password."' LIMIT 0, 30 ";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$count = mysql_num_rows($result);
if ($count == 0)
{
echo "Please Try Again!";
}
else
{
//$userid = "2";
session_register("email");
header("location:index.php");
}
}
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">
<table border=\"0\">
<tr>
<td>email</td>
<td>password</td>
</tr>
<tr>
<td><input type=\"text\" name=\"login_username\" class=\"username\" /></td>
<td><input type=\"text\" name=\"login_password\" class=\"username\" /></td>
<td><td><input type=\"submit\" value=\"Login\" /></td></td>
</tr>
</table>
</form>";
?> <?php
include("functions.php");
// Check if theres a sesh going on !
if(!isset($_SESSION['email']))
{
header("location:login.php"); //if not redirect to login
}
// If there is a session, the page won't redirect and the rest of the code will run
echo "yay";
echo "
<form action=\"index.php\" method=\"get\">
<input type=\"submit\" name=\"logout\" value=\"Log Out\">
</form>";
?> <?php
session_start();
if (isset($_GET['logout']))
{
session_destroy();
header("location:index.php");
}
mysql_connect("localhost", "joh001", "sWeS9e!p")or die("can't connect to the database");
mysql_select_db("joh001")or die("cannot detect database!");
$title = "WElcome";
?>