du8791069 2016-07-28 10:43
浏览 30

PHP PDO SESSION无法重定向

I am using session through login form , but when trying to login its not redirecting to index.php . please let me know where i am mistaken. below is my code for index and login

         <?php 
         session_start();

           if (!isset($_SESSION['user_name'])) {
            header("location: login.php");
             }
             else{
              echo "welcome $user_name";
             ?>

following with html

<!DOCTYPE html>
<html>
<head>
    <title>Admin Panel</title>
    <link rel="stylesheet" type="text/css" href="admin_style.css">
</head>
<body>

<h1>Welcome To Home Page</h1>

</body>
</html>

           <?php } ?>

below login.php code with form

            <?php
             session_start();
            ?>

<!DOCTYPE html>
<html>
<head>
    <title>Admin Login</title>
</head>
<body>
<form action="login.php" action="post">
    <table width="400" align="center" border="20">

    <tr>
        <td colspan="5" align="center" bgcolor="gray"><h1>Admin Login</h1></td>
    </tr>

    <tr>
        <td align="right">User Name:</td>
        <td><input type="text" name="user_name"></td>
    </tr>

    <tr>
        <td align="right">User Password</td>
        <td><input type="password" name="user_pass"></td>
    </tr>

    <tr>
        <td align="center" colspan="5"><input type="submit" name="login" value="Login"></td>
        
    </tr>
        
    </table>
</form>

</body>
</html>
    <?php 
include("connect.php");

if(isset($_POST['login'])) {

    $user_name = $_POST['user_name'];
    $user_pass = $_POST['user_pass'];

    $sth = $con->prepare("SELECT * FROM admin_login WHERE user_name='$user_name' AND user_password='$user_pass'");


     $sth->execute();


    if($sth->rowCount() > 0) {

        $_SESSION['user_name'] = $user_name;
        header("Location: index.php"); // Redirecting To index Page
        } else {
       echo "<script>alert('Username or Password is invalid')</script>";
       }  

}


?>

through this code i am just able to see on address bar line and no javascript alert: http://localhost/malala/admin/login.php?user_name=kitchen&user_pass=kitchen&login=Login

Please help ....

</div>
  • 写回答

1条回答 默认 最新

  • dongtang1966 2016-07-28 10:46
    关注

    http://localhost/malala/admin/login.php?user_name=kitchen&user_pass=kitchen&login=Login Send the variable as GET and you're looking for them as POST

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分