I have set the session on all pages in my admin panel like so:
session_start();
if(!isset($_SESSION['username']))
header("Location: login.php?e=please+login+first");
This seemed to be working properly on all my pages, but now when I refresh my page or click on a link, the page automatically redirects to login.php
. This seems to happen infrequently. I don't understand what is causing this problem
As an example, my menu bar is like:
home : doctors: hospitals: feedback
If I am on hospitals.php
, then after a few mins I click on feedback.php
(or any other link) I get redirected to login.php
. The next time if I again click on the link I will not get redirected
Here is my dologin.php code
$qry = "select * from admin where username='$uname' and password='$pwd'";
//echo $qry;exit;
$rs = mysql_query($qry,$con);
if($rec= mysql_fetch_array($rs))
{
$_SESSION['username'] = $rec['username'];
header("Location: index.php");
}
else if (empty($uname))
{
header("Location: login.php?e=Please+enter+username");
}
else
{
header("Location: login.php?e=Invalid+username+or+password");
}