Inconsistent page redirections in php 
<p>I have set the session on all pages in my admin panel like so:</p>

<pre><code>session_start();

if(!isset($_SESSION['username']))
   header("Location: login.php?e=please+login+first");
</code></pre>

<p>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 <code>login.php</code>. This seems to happen infrequently. I don't understand what is causing this problem</p>

<p>As an example, my menu bar is like:</p>

<pre><code>home : doctors: hospitals:  feedback
</code></pre>

<p>If I am on <code>hospitals.php</code>, then after a few mins I click on <code>feedback.php</code> (or any other link) I get redirected to <code>login.php</code>. The next time if I again click on the link I will not get redirected</p>

<p>Here is my dologin.php code</p>

<pre><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");
 }
</code></pre>
