Php 标题位置问题。似乎无法在if-else语句中找到问题

Php 标题位置问题。似乎无法在if-else语句中找到问题,php,function,redirect,header,Php,Function,Redirect,Header,我对以下PHP代码有一些问题: require '../core/connection.php'; require '../includes/functions.php'; if (isset($_SESSION['user_id'])) { if (isset($_POST['current_user_password'])) { $current_user_password = md5($_POST['current_user_password']);

我对以下PHP代码有一些问题:

require '../core/connection.php';
require '../includes/functions.php';
if (isset($_SESSION['user_id'])) {
    if (isset($_POST['current_user_password'])) {
        $current_user_password = md5($_POST['current_user_password']);
        if ($current_user_password != $_SESSION['user_password']) {
            header('Location:../edit_credentials.php?edit=password&error=current_password');
        } else {
            $new_password = $_POST['new_user_password'];
            $new_password2 = $_POST['new_user_password2'];
            if ($new_password == '' || ($new_password2 == '') {
                header('Location:../edit_credentials.php?edit=password&error=new_password_empty');
            }
            if ($new_password != $new_password2) {
                header('Location:../edit_credentials.php?edit=password&error=new_password_not_equal');
            } else {
                $new_password = md5($new_password);
                edit_user_password($user_id,$new_password);
            }
        }
    } else {
        echo 'current_user_password not set';
    }
} else {
    echo 'Session not set';
}
下面是函数:

function edit_user_password($user_id,$user_password){
    global $db;
    $user_password_data = $db->query('
        UPDATE `users`
        SET `user_password` = "'.$user_password.'" WHERE `user_id` = "'.$user_id.'";');
        $_SESSION['user_password'] = $user_password;
        $db->query($user_password_data);
        header("Location:../edit_credentials.php?saved=password");
}
除此之外,一切正常:

if ($new_password == '' || ($new_password2 == '') {
                header('Location:../edit_credentials.php?edit=password&error=new_password_empty');
            }
当谈到这个部分时,密码是空的,如果我用一个骰子('test')关闭重定向,它会工作,但它不会与重定向一起工作。你们知道为什么这样不行吗


提前感谢您的帮助。

您应该添加一个
出口标题('Location:…')后的code>呼叫。

否则脚本将继续运行。

无法工作不是一个适当的问题描述。告诉我们你的期望和真正发生的事情。你我的朋友是救世主。工作很有魅力,我学到了一些新东西。