I have been following some tutorials on creating a php and mysql based login system. I have the basics down, however simply trying to echo out the user username when they are logged in and cant seem do it.
When a user successfully logs in a session is creation with a value of 'authorised' this allows them to access the 'admin' page. This is where I would like to echo out their username. So I tried starting another session that stores their user name, this will be created the 'authorised' session is started i.e. when a user logs in. However trying to echo out either of those session on the admin page is proving impossible. i simply get an error stating "ndefined index: authorised in C:\wamp\www\Login\admin.php on line 27".
I wonder if you can help.
This is teh admin page, when the session 'athorised' is started they can access this page, this is where I want to echo out the username.
<?php
require_once 'classes/loginClass.php';
$login = new Login();
$login->confirm_Member();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, maximum-scale=1.0, minimum-scale=1.0, initial-scale=1.0" />
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="css/admin_styles.css" />
<link rel="stylesheet" type="text/css" href="css/admin_styles_large.css" />
<link rel="stylesheet" type="text/css" media="only screen and (min-width:50px) and (max-width:500px)" href="css/admin_styles_small.css" />
<link rel="stylesheet" type="text/css" media="only screen and (min-width:501px) and (max-width:800px)" href="css/admin_styles_medium.css" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="page">
<header>
<div class="user_container">
<p>Username: Chris</p>
<?php echo $_SESSION['user']; ?>
<a href="login.php?status=loggedout">Log Out</a>
</div>
</header>
<div class="widget_container">
<div class="widget_1"></div>
<div class="widget_2"></div>
<div class="widget_3"></div>
<div class="widget_4"></div>
</div>
<article>
</article>
<nav>
<a href="#">Dashboard</a>
<a href="#">Manage Users</a>
<a href="#">Manage Products</a>
</nav>
<footer>
© Web Assignment 2 - 2013
</footer>
</div>
</body>
</html>
And this is the class that logs them in:
<?php
require 'mysqlClass.php';
class Login {
public $user = 'Test';
function checkLogin($username, $password) {
$mysql = new Mysql();
$check_credentials = $mysql->verify_username_and_password($username, md5($password));
if($check_credentials) {
$_SESSION['status'] = 'authorised';
$_SESSION['user'] = $username;
header("location: admin.php");
} else return "Please enter a correct username and password.";
}
function logOutUser() {
if(isset($_SESSION['status'])) {
unset($_SESSION['status']);
if(isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time() - 10000);
session_destroy();
}
}
}
function confirm_Member() {
session_start();
if($_SESSION['status'] !='authorised') {
header("location: login.php");
}
}
}
?>