Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

php redirection not working

Ive got this register script that puts the information into a mysql database. now it all works fine and when someone does something wrong its says the error (e.g. "Username not defined")

but when it goes wrong it does not look very good because it just displays the message on an empty page, so i thought i would make it redirect to the form page and display the message there.

here is the working script

$forename = $_POST['forename'];      
$surname = $_POST['surname'];       
$email = $_POST['email'];    
$password = $_POST['password'];    
$username = $_POST['username'];

$errors = array();

 if(!$username) {

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

 }

 if(!$password) {

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

 }

and it continues.

now i just thought i could do this

 $errors = array();

 if(!$username) {

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

 }

 if(!$password) {

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

 }

but no, all it does is ignore it.

could someone please help me

please feel free to ask for more of the script if you need it

many thanks connor

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You cannot wrap a header in a array like that.

You just call the function, then it redirects.

header( 'Location: http://localhost/muiltabledistractions/#!/page_register_error-Username-is-not-defined' ) ;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...