The problem seems to be as follows: I open the browser. Point the browser to localhost/myproject/. login page is loaded on the browser. I enter the email address and password and click login. instead of going to the home page the login page reloaded again. I enter the same email address and password again and click login this time it goes to the home page correctly??. and something increase the ambiguity that the problem appears only for the first login. If I logout and login again from the same browser it respond from the first time. my login code:
<?php
session_start();
if (isset($_SESSION['email']))
header("location:" . $config_basedir);
if (isset($_POST['submit'])) {
$email = trim($_POST['email']);
$email = mysql_real_escape_string($email);
$password= trim($_POST['password']);
$password = mysql_real_escape_string($password);
$query = "select * from users where email= '" . $email .
"' and password= '" . md5($password) . "'";
$result = mysql_query($query, $con);
if ($result != NULL) {
if (mysql_num_rows($result) == 1) {
while ($row = mysql_fetch_array($result)) {
$_SESSION['email'] = $email;
}
header("location: " . $config_basedir);
}
echo "<p style='color:red ;font-size:15px'>****invalid login***</p>";
} else
echo "<p style='color:red ;font-size:15px'>****invalid login****</p>";
}
?>
<html>
<form method="post" action="<?php echo $_SERVER['SCRIPTNAME']; ?>">
<p><input type="text" name="email" value="" placeholder="Email address"></p>
<p><input type="password" name="password" value="" placeholder="Password"></p>
<p class="submit"><input type="submit" name="submit" value="Login"></p>
</form>
</html>
and at the Home page I use:
<?php
session_start();
if (!isset($_SESSION['email']))
header("location:" . $config_basedir . "login.php");
?>