Page should be stoping input

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
Little Spy
Forum Commoner
Posts: 31
Joined: Thu Oct 10, 2002 8:18 pm
Contact:

Page should be stoping input

Post by Little Spy »

i have the target to a form (registration form setup like this)

Code: Select all

<?php
	//Some standard checks
	if (strcmp($_POST['password'], $_POST['cpassword']) != 0) header("Location: error.php?errno=4");
	if (strlen($_POST['username']) < 3 || strlen($_POST['username']) > 18) header("Location: error.php?errno=5");
	if (strlen($_POST['password']) < 5) header("error.php?errno=6");
	if (strlen($_POST['email']) <= 0) header("error.php?errno=7");
	if (ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $$_POST['email']) == FALSE) header("Location: error.php?errno=10");;
	if (rows_query("SELECT username FROM user WHERE username = '$_POST[username]'") > 0) header("Location: error.php?errno=8");
	$_POST['byear'] = "19" . $_POST['byear'];
	if (checkdate($_POST['bmonth'], $_POST['bday'], $_POST['byear']) == FALSE) header("Location: error.php?errno=9");
	$time = time(); //Joindate
	$birthday = mktime(0, 0, 0, $_POST['bmonth'], $_POST['bday'], $_POST['byear']); //Make birthdate from input
	$password = md5($_POST['password']);
	$query = reg_query("INSERT INTO user (username, password, email, homepage, aim, icq, signature, joindate, birthdate, location, realname, favanime) VALUES ('$_POST[username]', '$password', '$_POST[email]', '$_POST[homepage]', '$_POST[aim]', '$_POST[icq]', '$_POST[signature]', '$time', '$birthday', '$_POST[location]', '$_POST[realname]', '$_POST[favanime]')");
	
	//set a cookie to show they are registered (not really 'protection' from multiple signups)
	$expiry = 60*60*24*365*100; //100years
	setcookie("registered", "1", time()+$expiry, "/");
	$page = new template("templates/register/done.html");
	$page->$linkroot = "";
	$page->CreatePage();
?>
whenever an error happens it should be going to error.php and stopping input on the rest of the page, however it shows the correct page for each error but goes alone with the rest of the page showing the last error page encountered and then adding the unfit user to the database, i have tried exit; after the header(); function but that doesnt work properly and I understand why, does anyone have any sugesstions?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post by kettle_drum »

After you use header() to redirect the use you must use exit; to stop the rest of the page from loading.
Post Reply