Loop prevent the users from logging to the page
<p>I have login page where users can authenticates them self and login.
There’s while loop portion which start automatic when page load which prevent the users from logging and keep looping until its meet the requirement and finish .
The loop check the file time stamp if the file time is less keep the user login else if its great then logout the user with session_destroy.
What exactly I need the loop portion start after the user login to the page and start the loop and count the time.</p>

<p>Here is my code please see and let me know where I have to do the fix. 
Thanks. </p>

<p>login interface 1 ifstatment.php which call auth.php</p>

<pre><code>&lt;html&gt;
&lt;body&gt;

&lt;h1&gt;Welcome To Internet HotSpot&lt;/h1&gt;

&lt;form action="auth.php" method="post"&gt;
Username: &lt;br&gt;&lt;input type="text" name="username"&gt;&lt;/br&gt;
Password: &lt;br&gt;&lt;input type="password" name="password"&gt;&lt;/br&gt;


&lt;div id="main"&gt;
&lt;div class="floatdiv"&gt;

&lt;input type="submit" name = 'submit' value= 'Login'&gt;
&lt;/form&gt;
&lt;/div&gt;

&lt;div class="floatdiv"&gt;

&lt;form method="POST" action="adminlogin1.php"&gt;
&lt;button type="submit"&gt;admin login&lt;/button&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/div&gt;


&lt;style type="text/css"&gt;
#main
{
position:relative;
    width:200px;
}

.floatdiv
{
float:left;
    width=80px
}
&lt;/style&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>auth.php script</p>

<pre><code>&lt;? ob_start(); ?&gt;

&lt;?php
session_start();

//connecting to database

$db = mysql_connect("localhost","sqldata","sqldata") or die(mysql_error());

//selecting our database

$db_select = mysql_select_db("accounts", $db) or die(mysql_error());

ini_set('session.bug_compat_42',0);
ini_set('session.bug_compat_warn',0);

//Retrieving data from html form

$username = $_POST['username'];

$password = $_POST['password'];

$_SESSION['username']= $_POST['username'];

//for mysql injection (security reasons)

$username = mysql_real_escape_string($username);

$password = mysql_real_escape_string($password);

//checking if such data exist in our database and display result

$result= mysql_query("select * from uptable where username = '$username' ");

$row = mysql_fetch_array( $result );

$storedPassword = $row['password'];

$hash= crypt($password,$storedPassword)===$storedPassword;

if ($hash)
{

$_SESSION['logged_in'] = true;
header("Location: check.php");
exit;
}

else
{

echo'Error Login Failed';
echo "&lt;form action= 'ifstatment.php' method='post'&gt;";
echo "&lt;input type='submit' name='submit' value='Retrun To Login Page'&gt;";
echo "&lt;/form&gt;";

}

?&gt;

&lt;? ob_flush(); ?&gt;
</code></pre>

<p>check.php script </p>

<pre><code>&lt;? ob_start(); ?&gt;

&lt;?php

if (!isset($_SERVER['HTTP_REFERER']))
{

header("location: auth.php");
exit;
}

session_start();
$username= $_SESSION['username'];

echo "&lt;br&gt; Hi $username.&lt;/br&gt;";

echo "&lt;br&gt;You Have Logged In Successfully.&lt;/br&gt;";

$ip = $_SERVER['REMOTE_ADDR'];

$txt="Your ip Address Is ";

echo $txt . " " .  $ip;

exec("/usr/bin/sudo -u apache sudo  /sbin/iptables  -I INPUT -s $ip -j ACCEPT");

ini_set('max_execution_time', 300);

$filename = 'test';

$loop= true;

while ($loop)

{

if (time()- filemtime($filename) &gt; 60 )
{
session_destroy();

session_unset();

header("location:ifstatment.php");

exit();

$loop= false;

}
}


?&gt;
&lt;? ob_flush(); ?&gt;

&lt;html&gt;
&lt;body&gt;
&lt;form method="POST" action="logout.php"&gt;
&lt;button type="submit"&gt;Logout&lt;/button&gt;
&lt;/form&gt;

&lt;br&gt; update your account password &lt;/br&gt;

&lt;form method="POST" action="pwdchange.php"&gt;
&lt;button type="submit"&gt;update&lt;/button&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
