dongzhan8001 2019-04-04 17:12 采纳率: 0%
浏览 56

虽然用户名和密码在cpanel中是正确的,但页面不会重定向

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 目详情-五一模拟赛详情页
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b