hier is de code
Checkuser class
<?php
class CheckUser
{
protected $_username;
protected $_password;
public function __construct($username, $password)
{
require_once './core_classes/DatabaseFunctions.php';
require_once 'Escaper.php';
$escaper = new escaper();
$database = new DatabaseFunctions('localhost', 'root', 'school12', 'contapp');
$this->_username = $escaper->escaper($username);
$this->_password = $escaper->escaper($password);
}
public function goToLogin()
{
sleep(2);
header('Location: http://127.0.0.1/contapp/index.php';);
}
public function loggingIn()
{
sleep(2);
header('Location: http://127.0.0.1/contapp/test3.php';);
}
public function checkIsLoggedIn()
{
if ($_SESSION['logged_in'] != true)
{
$this->goToLogin();
}
}
public function AuthenticateUser()
{
require_once './core_classes/DatabaseFunctions.php';
$database = new DatabaseFunctions('localhost', 'root', 'school12', 'contapp');
private $username = $this->_username;
private $password = $this->_password;
try
{
$sql = "SELECT id, username, password, securitylevel FROM users
WHERE username='$username' && password='$password'";
$res = $database->selectSQL($sql);
if( mysql_num_rows($res) == 1)
{
$row = $database->fetchArray($row);
$_SESSION['id'] = $row['id'];
$_SESSION['username'] = $row['username'];
$_SESSION['password'] = $row['password'];
$_SESSION['securitylevel'] = $row['securitylevel'];
$_SESSION['logged_in'] = true;
$this->loggingIn();
}
else
{
throw new Exception("This combination of credidentials doesn't exist.");
}
}
catch (Exception $e)
{
echo 'Error: '. $e->getMessage() . '<br />';
echo 'Code: ' . $e->getCode() . '<br />';
echo 'File: ' . $e->getFile() . '<br />';
echo 'Line: ' . $e->getLine() . '<br />';
}
}
}
?>
Test2.php << de login pagina
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
require_once 'classes/CheckUser.php';
$user = new CheckUser($_POST['1'], $_POST['2']);
$user->AuthenticateUser();
}
?>
<html>
<head>
</head>
<body>
<form action="<?php $PHP_SELF ?>" method="post">
<input type="text" name="1" />
<input type="text" name="2" />
<input type="submit" value="Save Company" />
</form>
</body>
</html>
test3.php <<< de pagina om de sessie te testen
<?php
require_once 'classes/CheckUser.php';
$user = new CheckUser($_SESSION['username'], $_SESSION['password']);
?><html>
<head>
</head>
<body>
Welcome at test3
<?php print_r($_SESSION); ?>
</body>
</html>