hye guys..i know this question have been post million of times..im new to php btw..right now im trying to make multilevel user login form using session..but im little confused why my session didt work..i already tried to make a redirect to login page if the user is not login yet..it seem the code read that my session does not pass yet if i try to run from the homepage..but the problem is it does not redirect to the login form even the session is not exist..i have tried to clear all the cache and cookies but still did not work..sorry for my broken language..i hope u guys understand what my question is and tell me what is problem with my codes..ty
loginFunction.php
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
@session_start();
include ('Connections/connect.php');
if(isset($_POST['submit'])) {
$username = $mysqli->real_escape_string($_POST['txtUsername']);
$password = $mysqli->real_escape_string($_POST['txtPassword']);
if ($username == "" || $password == "") {
?>
<script> alert('Please enter username and password ...')
window.location='index.html'</script>
<?php
} else {
$query = ("SELECT * FROM tbluser WHERE username='$username' AND password='$password'");
$result = $mysqli->query($query);
$data = $result->fetch_array();
$count = $result->num_rows;
if ($count>0) {
if ($data['role'] == "partner") {
@$_SESSION['partner'] = $data['userId'];
?>
<script>alert('You are log as industrial partner ...')
window.location='homePartner.html'</script>
<?php
} else if ($data['role'] == "student") {
@$_SESSION['student'] = $data['userId'];
?>
<script>alert('You are log as student ...')
window.location='homeStudent.html'</script>
<?php
} else if ($data['role'] == "admin") {
@$_SESSION['admin'] = $data['userId'];
?>
<script>alert('You are log as admin ...')
window.location='homeAdmin.html'</script>
<?php
}
} else {
?>
<script>
alert('Username or password does not match ...')
window.location='index.html'
</script>
<?php
}
}
}
?>
homeStudent.html
<?php
session_start();
include ('Connections/connect.php');
if(@$_SESSION['student'] || @$_SESSION['admin'] || @$_SESSION['partner'] ) {
?>
<html>
//html stuff
</html>
<?php
} else {
header("location: index.html");
exit;
?>
<script>
alert('Please login first ...')
</script>
<?php
}
?>