After login I store in session for the user, the username
and the user id
. After the login, the user goes to his / her page they select their name
so to see their statistical scores from the evaluations. This name
is stored in session too. But I don't know how can I control what the user can see. I don't know to how to do it.
loginForm.php
<html>
<head><link rel="stylesheet" type="text/css" href="../../statistics/style.css">
</head>
<body>
<div id="login">
<h3>Login</h3>
<form action = "login.php" method = "POST">
<label>Username: </label> <br/>
<input class="inputfield" type="text" name="username" size="20"/> <br /><br/>
<label>Password: </label> <br/>
<input class="inputfield" type="password" name="password" size="20"/> <br /><br/>
<input type="submit" value="Login" name="submit"/>
<input type="reset" name="reset" value="Clear"/>
</form>
<!--End of Login-->
</div>
</body>
</html>
login.php
<?php
require ('connect.php');
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if ($username && $password) {
$check = mysql_query("SELECT * FROM users WHERE username='".$username."' AND password= '".$password."'");
$rows = mysql_num_rows($check);
if(mysql_num_rows($check) != 0){
session_start();
$run_login =mysql_fetch_array($check);
$uid = $run_login['id'];
$_SESSION['uid'] = ['uid'];
$_SESSION['username']=$_POST['username'];
header("location:../../statistics/home.php");
}
else{
die("Could not find the Username or password.");
}
}
else {
echo "Please fill all the fields.";
}
}
?>
lecturer.php
<?php
include 'connect.php';
$years = array(
2005,
2006,
2007
);
$lecturers = array(
'dimopoulos',
'lagkas',
'kehagias',
'chrysochoou'
);
if(isset($_POST['submit'])){
$year = mysql_real_escape_string($_POST['year']);
$lecturer = mysql_real_escape_string($_POST['lecturer']);
session_start();
/*checks if the user types the url of the page that he is not allowed to use, it leads him to the main page so to login*/
if(!isset($_SESSION['username'])){
header("location:../../statistics/main.htm");
}
$username=$_SESSION['username'];
/*checks if the lecturer name the user selected matches their username*/
if(isset($_POST['lecturer'])== isset($_SESSION['username'])){
$_SESSION['lecturer'] = $_POST['lecturer'];
if (in_array($lecturer, $lecturers) && in_array($year, $years)) {
$sql = "SELECT unit_name,a1,a2,a3,l1,l2,l3,l4,l5,l6,l7,lavg,r1,r2,u1,u2,u3 FROM $lecturer WHERE year=$year";
$result = mysql_query($sql);
}
else {
echo "No data found";
}
}
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../../statistics/style.css">
</head>
<body>
<div id="container">
<table id="table" width="900" border="1" cellspacing="1">
<tr>
<td>Unit Name</td>
<td>A1 </td>
<td>A2 </td>
<td>A3 </td>
<td>L1 </td>
<td>L2 </td>
<td>L3 </td>
<td>L4 </td>
<td>L5 </td>
<td>L6 </td>
<td>L7 </td>
<td>LAVG </td>
<td>R1 </td>
<td>R2 </td>
<td>U1 </td>
<td>U2 </td>
<td>U3 </td>
</tr>
<?php
while($unit=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>".$unit['unit_name']."</td>";
echo "<td>".$unit['a1']."</td>";
echo "<td>".$unit['a2']."</td>";
echo "<td>".$unit['a3']."</td>";
echo "<td>".$unit['l1']."</td>";
echo "<td>".$unit['l2']."</td>";
echo "<td>".$unit['l3']."</td>";
echo "<td>".$unit['l4']."</td>";
echo "<td>".$unit['l5']."</td>";
echo "<td>".$unit['l6']."</td>";
echo "<td>".$unit['l7']."</td>";
echo "<td>".$unit['lavg']."</td>";
echo "<td>".$unit['r1']."</td>";
echo "<td>".$unit['r2']."</td>";
echo "<td>".$unit['u1']."</td>";
echo "<td>".$unit['u2']."</td>";
echo "<td>".$unit['u3']."</td>";
echo "</tr>";
}
?>
</table>
</div>
lecturerForm.php
<form name="myform" action="lecturer.php" method="POST" >
<b>Lecturers:<b/>
<select name="lecturer">
<option value="Choose">Please select..</option>
<?php
$sql=mysql_query("SELECT lec_name FROM lecturer");
while($row=mysql_fetch_array($sql)){
echo "<option value='".$row['lec_name']."'>".$row['lec_name']."</option>";
}
?>
</select><br/><br/>
<b>Year:<b/>
<select name="year">
<option value="Choose">Please select..</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option></select><br/><br/>
<br/>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Clear">
</form>