I fixed your code, here are the errors i found
1)If you are gonna call $_SESSION, then you must call session_start()
2)You forgot to select the Database to use, (i.e forgot to call mysql_select_db)
3)In your logout link, you say go to "process.php" but how is process.php supposed to know which function you want to use? To remedy this i modified
the url process.php?action=logout . Now the process.php can check if the url contains a action key in $_GET and check it's value is "logout" and then it can logout the user.
Also, the main purpose of classes is to group related methods and variables, so the class can be reused as many times as need in the form of objects mainly ($p = new class(), $p is an object,)
config.php
<?php
//Configuration File
session_start();
define("DB_HOST","localhost"); //Define Host
define("DB_USER","root"); //Define Username
define("DB_PASS",""); //Define Password
define("DB","practice"); //Define the db
define("DB_TABLE","user"); //Define the db
//Connect to the Server
$connection = mysql_connect(DB_HOST,DB_USER,DB_PASS) or die (mysql_error());
//Connect to the Databse
mysql_select_db(DB, $connection);
?>
functions.php
<?php
include ("config.php");
//Classes and functions!
class memberssystem
{
function check_login($username,$password)
{
$result = mysql_query("SELECT * FROM user WHERE username ='$username'") or die(mysql_error());
$check_rows = mysql_num_rows($result) or die(mysql_error());
if($check_rows != 1)
{
return false;
}
else
{
while($row = mysql_fetch_array($result))
{
if($row['username'] != $username || $row['password'] != $password)
{
return false;
}
else
return true; //Success!
}
}
}
public function logout()
{
session_destroy();
header("location: index.php");
die();
}
}
$members = new memberssystem();
?>
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login Page!</title>
</head>
<body>
<?php
session_start();
if(isset($_SESSION['username']))
{
//Already logged in member!
header("location: members.php");
}
?>
<table>
<form action='process.php' method='post'>
<tr>
<td>Username: </td>
<td><input type='text' name='username' /></td>
</tr>
<tr>
<td>Password: </td>
<td><input type='password' name='password' /></td>
</tr>
<tr>
<td>
<input type='submit' value='login' name='submit' />
</td>
</tr>
</form>
</table>
</body>
</html>
members.php
<?php
session_start();
//Member's Page!
if(!$_SESSION['username'])
{
header("location: index.php");
}
?>
<html>
<h1>Member's Page!</h1>
<p>Welcome to the Member's Page! For right now, you can not do anything :/ but you can <a name='submit_logout' href='process.php?action=logout'>logout</a> :} </p>
</html>
process.php
<?php
include("functions.php");
//Process for each form!
if(isset($_POST['submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$login = $members->check_login($username,$password);
if($login)
{
$_SESSION['username'] = $username;
header("location: members.php");
die();
}
}
if(isset($_GET['action']) && $_GET['action'] == 'logout')
{
$members->logout();
}
?>