Beginner Question - HTML and PHP - Sorry

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dudds
Forum Newbie
Posts: 2
Joined: Thu Nov 06, 2008 6:43 am

Beginner Question - HTML and PHP - Sorry

Post 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!!
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Re: Beginner Question - HTML and PHP - Sorry

Post 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.
dudds
Forum Newbie
Posts: 2
Joined: Thu Nov 06, 2008 6:43 am

Re: Beginner Question - HTML and PHP - Sorry

Post by dudds »

thanks heaps someberry!! Much appreciated.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Beginner Question - HTML and PHP - Sorry

Post 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.
Post Reply