Oh, I might want to show you my index code and my connect code!
index:
<?php
include('connect.php');
if($loggedin == '0')
{
if(isset($_POST['submit']))
{
// Make sure all forms were filled out.
if((!isset($_POST['username'])) || (!isset($_POST['pass']))
|| ($_POST['username'] == '') || ($_POST['pass'] == ''))
die("Please fill out the form completely. <br><br>
<a href=index.php>Continue</a>");
// Get user's record from database
$player = @mysql_query("SELECT id, username, password, registered, lastlogin FROM players WHERE username = '".$_POST['username']."'");
$player = @mysql_fetch_assoc($player);
if($player['id'] == false)
die("Sorry, that user is not in our database.<br><br>
<a href=index.php>Back</a>");
else if($player['password'] != md5($_POST['pass']))
die("Wrong password!<br><br>
<a href=index.php>Back</a>");
// set session variables
$_SESSION['id'] = $player['id'];
$_SESSION['username'] = $player['username'];
$_SESSION['password'] = $player['password'];
// update last login
$date = date("m/d/y");
$update = @mysql_query("UPDATE players SET lastlogin = '$date' WHERE id = '".$_SESSION['id']."'");
echo 'You are now logged in!';
}
else
{
echo 'You are not logged in. <br><br>
<form action=index.php method=post>
Username: <input type=text name=username><br>
Password: <input type=password name=pass><br>
<input type=submit name=submit value=Submit>
</form>
Would you like to <a href=register.php>register?</a>';
}
}
else
{
echo 'You are logged in!
Welcome to my game, '.$_SESSION['username'].'!
<br><br>
<a href=logout.php>Click Here to Logout</a>';
}
?>
Connect:
<?php
// This script will connect the user to your mySQL database.
// It will also check it they're logged in or not.
// It should be included on every page you create.
// Set the variables below to match your settings
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'mygame';
$link = mysql_pconnect($dbhost, $dbuser, $dbpass)
or die("Could not connect to server.");
$selectdb = mysql_select_db($dbname, $link)
or die("Could not connect to database.");
// Check to see if user is logged in
session_start();
if((!isset($_SESSION['id'])) || (!isset($_SESSION['username'])) ||
(!isset($_SESSION['password'])))
{
unset($_SESSION['username']);
unset($_SESSION['password']);
unset($_SESSION['id']);
$loggedin = 0;
}
else
{
$loggedin = 1;
}
?>
Thanks again!