I have a login feature in a project I am working on that is behaving strangely. The symptom is that when a person tries to log in with the correct info, they are kicked out to the login page again. They enter their stuff a second time and they then can get in. The funny thing is, that in my code, nowhere to I have a conditional to kick the user back tot he login page, just to give errors or let them in. My code as it stands is below:
<?php
if((!$username)|(!$password)){
echo "<span class='whitey1'>Information Was Not Entered</span><p>";
echo "<a href='index.php'>Try login again</a><p>";
echo "If you have forgotten your password, use the link below to have the <br>password sent to the instructor email address. <p><a href='send_pass.php'> email password to instructor address</a>";
echo"</td>
<td width='15%' class='sides'><img src='../images/shim.gif' width='5' height='700' border='0'></td>
</tr>
</table>
</body>
</html>";
exit;
}
#encrypt password
$password=crypt($password,'xx');
#grab user name if it is there
$username_result = mysql_query("SELECT log FROM $prefix"."_instructor where log= '$username'",$db);
$username_row = mysql_fetch_row($username_result);
$correct_username = $username_row[0];
$log_num = mysql_num_rows($username_result);
if($log_num == "1") {
#grab pass to compare
$pass_result = mysql_query("SELECT pass FROM $prefix"."_instructor where log= '$correct_username'",$db);
$pass_row = mysql_fetch_row($pass_result);
$correct_pass = crypt($pass_row[0],'xx');
if($password == $correct_pass) {
begin session, register user name
session_start();
session_register("username");
#redirect
header("Location:".$admin_path."admin_home.php");
}
else {
echo "<span class='whitey1'>Password Incorrect</span><p>";
echo "<a href='index.php'>Try login again</a><p>";
echo "If you have forgotten your password, use the link below to have the <br>password sent to the instructor email address. <p><a href='send_pass.php'> email password to instructor address</a>";
}
}
else {
echo "<span class='whitey1'>User Name Incorrect</span><p>";
echo "<a href='index.php'>Try login again</a><p>";
echo "If you have forgotten your password, use the link below to have the <br>password sent to the instructor email address. <p><a href='send_pass.php'> email password to instructor address</a>";
}
?>
I am stumped and would appreciate any insight.
Thanks