php重定向无法正常工作

con*_*r.p 0 php

我有这个寄存器脚本,将信息放入mysql数据库.现在一切正常,当有人做错事时,它会说出错误(例如"用户名未定义")

但是当它出错时它看起来不太好,因为它只是在空白页面上显示消息,所以我想我会将它重定向到表单页面并在那里显示消息.

这是工作脚本

$forename = $_POST['forename'];      
$surname = $_POST['surname'];       
$email = $_POST['email'];    
$password = $_POST['password'];    
$username = $_POST['username'];
Run Code Online (Sandbox Code Playgroud)

$errors = array();

 if(!$username) {

    $errors[] = "Username is not defined";

 }

 if(!$password) {

    $errors[] = "Password is not defined";

 }
Run Code Online (Sandbox Code Playgroud)

它继续.

现在我只是觉得我能做到这一点

 $errors = array();

 if(!$username) {

    $errors[] = header( 'Location: http://localhost/muiltabledistractions/#!/page_register_error-Username-is-not-defined' ) ;

 }

 if(!$password) {

    $errors[] = "Password is not defined";

 }
Run Code Online (Sandbox Code Playgroud)

但不,它只是忽略它.

有人可以帮助我

如果您需要,请随时询问更多脚本

非常感谢康纳

Jan*_*aek 5

您无法将标头包装在这样的数组中.

你只需调用该函数,然后重定向.

header( 'Location: http://localhost/muiltabledistractions/#!/page_register_error-Username-is-not-defined' ) ;
Run Code Online (Sandbox Code Playgroud)