Jump to content

Warning: Cannot modify header information


chiba

Recommended Posts

Why am I getting this error message after I fill out the form and press submit? The data is entered correctly into the database, but the header doesn't work.  :'(

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/27/9433527/html/site/includes/overall/header.php:3) in /home/content/27/9433527/html/site/register.php on line 69

 

<?php
include 'core/init.php';
include 'includes/overall/header.php';
if(empty($_POST)===false)
{
$required_fields = array('username','password','password_again','first_name','last_name','email');
foreach ($_POST as $key=>$value)
{
	if (empty($value) && in_array($key, $required_fields)===true)
	{
		//if one error is found then break out
		$errors[] = 'Fields marked with an asterisk are required';
		break 1;
	}
}
if(empty($errors)===true)
{
	// triple === type checks as well as the value
	if (user_exists($_POST['username']) ===true)
	{
		$errors[] = 'Sorry the username \''.htmlentities($_POST['username']) . '\' is already taken.';	
	}
	if (preg_match("/\\s/",$_POST['username']) == true)
	{

		$errors[] = 'Your username must not contain any spaces.';	
	}
	if (strlen($_POST['password']) < 6)
	{
		$errors[] = 'Your password must be at least 6 characters';
	}
	if ($_POST['password'] !== $_POST['password_again'])
	{
		$errors[] = 'Your passwords do not match';	
	}
	if (filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)===false)
	{
		$errors[] = 'A valid email address is required';

	}
	if (email_exists($_POST['email'])===true)
	{
		$errors[] = 'Sorry the email \'' .$_POST['email'] . '\' is already in use';
	}
}
}
?>
<h1>Register</h1>
<?php
if (isset($_GET['sucess']) && empty($_GET['sucess']))
{
echo 'You\'ve been registered sucessfully.';
}
else
{
	if (empty($_POST) === false && empty($errors)===true)
	{
		$register_data = array(
			'username' => $_POST['username'],
			'password' => $_POST['password'],
			'first_name' => $_POST['first_name'],
			'last_name' => $_POST['last_name'],
			'email' => $_POST['email']
		);
		register_user($register_data);
		header('Location: register.php?sucess');
		exit();
	}
	else if (empty($errors) === false)
	{
		echo output_errors($errors);	
	}
?>
<p>Please fill out the form below to register an account.</p>
<form action="" method="post">
	<ul>
		<li>
		Username*:<br />
		<input type="text" name="username">
		</li>
		<li>
		Password*<br />
		<input type="password" name="password">
		</li>
		<li>
		Password again*<br />
		<input type="password" name="password_again">
		</li>
		<li>
		First Name*:<br />
		<input type="text" name="first_name">
		</li>
		<li>
		Last Name*:<br />
		<input type="text" name="last_name">
		</li>
		<li>
		Email address*:<br />
		<input type="text" name="email">
		</li>
		<li>
		<input type="submit" value="Register">
		</li>
	</ul>
</form>
<?php
}
include 'includes/overall/footer.php'; 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.