I built a web application using PHP and Mysql. It has a login Section. It is working fine and everything ok on my local server. But when I uploaded this app on live server the redirect function is not working any more. My code:
signin.php:
<form action="do_login.php" method="post">
<input name="user" type="text" id="user" size="25" placeholder="Username" />
<input name="password" type="password" id="password" size="25" placeholder="Password" />
<input name="submit" type="submit" value="Login" class="submit"/>
</form>
do_login.php:
<?php
include 'includes/dbConnect.php';
$my_user = $_POST['user'];
$my_password = $_POST['password'];
if ($my_user == '' || $my_password == '')
{
$myURL = 'error.php?eType=pass';
header('Location: '.$myURL);
exit;
}
$result = mysql_query("SELECT * FROM users where username = '$my_user' and password = '$my_password'") or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
$get_info = mysql_fetch_row($result);
if (mysql_num_rows($result) > 0)
{
session_start();
$_SESSION['login_status'] = "yes" ;
$_SESSION['email'] = $get_info['3'];
$_SESSION['full_name'] = $get_info['0'];
$myURL = 'admin.php';
header('Location: '.$myURL);
}
else
{
$myURL = 'error.php?eType=wrong';
header('Location: '.$myURL);
exit;
}
?>
When a user login successfully the browser takes to do_login.php
and displays a blank page that does not redirect to admin.php
on live server but on localhost it redirect to admin.php
. When I manually go to admin.php
, which has restrictions so that only logged in users can access it, I can access it that means I have been logged in and works fine.
Where is the mistake?