I have an index.php or a login page.The scenario on my webpage is when i successfully login and i accidentally press the back button the login page appear again and when i try to login again i could login again, which is not good.
here is my code:
<?php
session_start();
if(isset($_SESSION['USER_ID'])){
exit("you can't login in again when your all ready logged!");
}
//require_once 'conn.php';
$db_name="dspi";
mysql_connect("localhost", "root", "") or die("Cannot connect to server");
mysql_select_db("$db_name")or die("Cannot select DB");
$department = mysql_real_escape_string($_POST['department']);
$username = mysql_real_escape_string($_POST['username']);
$sql=mysql_query("SELECT `Department`, `Username` FROM `tbllogin` WHERE `Department` = '{$department}' AND Username = '{$username}'") or die(mysql_error());
$ct = mysql_num_rows($sql);
if($ct == 1) {
$row = mysql_fetch_assoc($sql);
if($row['Department']=='Accounting') {
header('location: Company.php');
} elseif($row['Department']=='Engineering') {
header('location: Company.php');
} elseif($row['Department']=='Finishing_Goods') {
header('location: Company.php');
} elseif($row['Department']=='HRAD') {
header('location: Company.php');
} elseif($row['Department']=='MIS') {
header('location:Company.php');
} elseif($row['Department']=='Packaging_and_Design') {
header('location:Company.php');
} elseif($row['Department']=='Production') {
header('location:Company.php');
} elseif($row['Department']=='Purchasing_Logistic') {
header('location:Company.php');
} elseif($row['Department']=='QA_and_Technical') {
header('location:Company.php');
} elseif($row['Department']=='Supply_Chain') {
header('location:Company.php');
}
else {
header('location:index.php');
echo"Incorrect Username or Department";
}
}
?>


Sign In
Create Account


Back to top









