Page 1 of 1

Beginner Question - HTML and PHP - Sorry

Posted: Thu Nov 06, 2008 6:50 am
by dudds
Sorry for the lame question, but I'm teaching myself php and run into a problem that I can't think of a solution for at the moment. I have a HTML form that includes asking a user to enter in a password and then verify that password by typing it in again. The submit button then calls a php script that I'd like to check to see whether the two passwords were entered in the same and then either display one HTML page or another based on whether the passwords entered were the same or not.

A gentle nudge in the right direction would be appreciated if anyone can take the time to help.

Thanks in advance!!

Re: Beginner Question - HTML and PHP - Sorry

Posted: Thu Nov 06, 2008 7:02 am
by someberry

Code: Select all

<?php
// All your other code...
 
if ($_POST['password'] == $_POST['password_verify']) {
   header('Location: same-password.php'); exit();
} else {
   header('Location: different-password.php'); exit();
}
 
// And the rest of your code...
Depending on how you are setup you might need to put ob_start() at the top of the script.

Re: Beginner Question - HTML and PHP - Sorry

Posted: Thu Nov 06, 2008 7:06 am
by dudds
thanks heaps someberry!! Much appreciated.

Re: Beginner Question - HTML and PHP - Sorry

Posted: Thu Nov 06, 2008 11:03 am
by RobertGonzalez
There should be no need for output buffering here (using the ob_* family of functions). That is a bandaid for writing unclean code in many cases. Redirects being one of those cases.

Also, when redirecting with a header call make sure to use full uris, not relative ones. The HTTP 1.1 spec states that a full URI is required. Plus it just makes good clean coding sense.