dongmufen8105 2018-02-26 10:36
浏览 37
已采纳

PHP POST请求重定向到root / xampp仪表板

I have a login page with a form with POST method and no action defined (or action to self). I use some functions to do the login, and when some field of the form is left empty or the login credentials are not valid, I´m being redirected to XAMPP dashboard. Its like as if my else statement is not kicking in. Any idea why?

if(ifItIsMethod('post')){

    if(isset($_POST['username']) && isset($_POST['password'])){

        login_user($_POST['username'], $_POST['password']);
    }else{
        echo "bla bla";
    }
}

I tried else{ header(..)} and nothing happens, it just redirects to dashboard.

I have a test version online where the same happens, its here: http://hotfol.com/cms/login_page.php

Thank you!!

Edit: functions

function ifItIsMethod($method=null){

    if($_SERVER['REQUEST_METHOD'] == strtoupper($method)){
        return true;
    }else{
        return false;
    }
}

function login_user($typed_username, $typed_password){
    global $connection;


$typed_username = escape($typed_username);
$typed_password = escape($typed_password);


$query = "SELECT * FROM users WHERE username = '$typed_username'";
$select_user_query = mysqli_query($connection, $query);
if(!$select_user_query) {
    die ("query failed" . mysqli_error($connection));
}

$row = mysqli_fetch_assoc($select_user_query);
    $user_id    = escape($row['user_id']);
    $username   = escape($row['username']);
    $password   = escape($row['user_password']);
    $firstname  = escape($row['user_firstname']);
    $lastname   = escape($row['user_lastname']);
    $user_role  = escape($row['user_role']);


    if (password_verify($typed_password, $password)) {

    $_SESSION['username']  = $username;
    $_SESSION['firstname'] = $firstname;
    $_SESSION['lastname']  = $lastname;
    $_SESSION['user_role'] = $user_role;
    $_SESSION['user_id']   = $user_id;

    header('Location: admin/index.php');
}else{
    header('Location: ../index.php');
    }
}
  • 写回答

1条回答 默认 最新

  • douzhi9478 2018-02-26 10:41
    关注

    Your inner if statement is always true, but you cannot login when one is empty. Both username and password are always set, but one of them is empty (still set) and the login_user function receives empty data so it cannot login a user. Use empty() - it shows true when there is an ampty string.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog