<?
session_start();
ob_start();
require_once('includes/mysql_connect.php');
if(isset($_SESSION['username']) && isset($_SESSION['password'])) {
//REDIRECT TO USERS PROFILE...
header("Location: myaccount.php");
exit;
} //end if logged in
//IF SUBMIT BUTTON PRESSED
if(isset($_POST['submit'])) {
if(!$_POST['username']) die("Error: You must enter your username before logging in.");
if(!$_POST['password']) die("Error: You must enter your password before logging in.");
//set cookie if checked
if(!empty($_POST['stay_in'])) {
$joined =''.$_POST['username'].'[]'.md5($_POST['password']).'';
setcookie('login_cookie', $joined, 2147483647, '/', '.www.yoursite.com');
} //end if
//verify user...
$get_user = mysql_query("SELECT * FROM `members` WHERE username = '".$_POST['username']."' AND password = '".md5($_POST['password'])."' limit 1");
$q = mysql_fetch_object($get_user);
if(!$q) die("Login Failure: An error occured, please verify your username and password are correct.");
//set session variables
$_SESSION['logged_in'] = $q['user_id'];
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
session_write_close();
header("Location: myaccount.php");
exit;
} else {
//show login form
?>
Bookmarks