I created php web application and it is working in my localhost.In addition to that it was working more than one year in cpanel hosting and i change domain and hosting provider. Now i am unable to login to my system. it does not show any error. what i can understand is session is not creating properly. when i went dashboard, it will redirect to again same login page.
Because of Session error, i created file which has only session
and just if statement
. it is working fine.
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$user_name = (isset($_POST['txt_username']) ? $_POST['txt_username'] : null);
$password = md5($_POST['txt_password']);
if (!empty($user_name) && !empty($password)) {
$sql = "SELECT * FROM user WHERE User_Name='$user_name' && Password='$password'";
$result = mysqli_query($conn, $sql);
if ($row = mysqli_num_rows($result) == 1) {
$_SESSION['username'] = $user_name;
$_SESSION['password'] = $password;
//header("location:htdocs/dashbd.php");
// echo '<script type="text/javascript">';
// echo "<script>location='htdocs/dashbd.php'</script>";
// echo 'alert("User name or Password is Incorrect");';
echo 'window.location = "htdocs/dashbd.php";';
// echo '</script>';
// } else {
// echo"error";
if(isset($_SESSION['username'])){
header("location:htdocs/dashbd.php");
echo 'window.location = "htdocs/dashbd.php";';
}
}
} else {
echo '<script type="text/javascript">';
echo 'alert("User name or Password is Incorrect");';
echo 'window.location = "index.php";';
echo '</script>';
}
} else {
echo '<script type="text/javascript">';
// echo 'alert("Username And Password Cannot Be Empty");';
// echo'getElementById("#feedback").innerHTML="mukuth nene";';
//echo 'window.location = "index.php";';
echo '</script>';
}
?>
when user name and password is correct it needs to redirect to htdocs/dashboard.php. in current situation wont.