登录后无法重定向到user_panel页面... header()无法正常工作

时间:2017-03-28 07:34:10

标签: php

   <?php
    if(isset($_POST['submit'])){
        $con=mysqli_connect("localhost","root","") or die("Failed to connect to MySQL: " .mysqli_connect_error()); 
        $db=mysqli_select_db($con,"users") or die("Failed to connect to MySQL: " .mysqli_connect_error());
        $count=0;
        $username = $_POST['username']; 
        $password = $_POST['password'];
        $query1 = "SELECT * FROM user_info WHERE Username= '$_POST[username]' && Password= '$_POST[password]'";
        $res = mysqli_query($con, $query1) or die(mysqli_connect_error());
        $count = mysqli_num_rows($res);
        if($count>0){
            session_start();
    $_SESSION['username'] = $username;
    header ("Location: user_panel.php");
        }
        else{
            echo "Incorret username or password ...";
        }
    }
    ?>

2 个答案:

答案 0 :(得分:0)

在标题位置使用fullpath,如下所示

<?php
$baseurl = "http://examplesite.com/";

header("location: ".$baseurl."user_panel.php");
?>

答案 1 :(得分:0)

你也可以通过javascript实现。

window.location.href='user_panel.php';