grabenair Posted August 3, 2012 Report Share Posted August 3, 2012 I am building a custom CMS. My problem is on the register user page. When I redirect after the user files out the form to register and clicks on the register button the form goes away and is replaced with a massage you have been registered check you email to activate. This works perfect in xampp on windows but when I put it up live I get this error: Warning: Cannot modify header information - headers already sent by (output started at /home/sassy/public_html/cms/includes/overall/header.php:3) in /home/sassy/public_html/cms/register.php on line 54 When I commit out the redirect line it works but with no massage. What I am using to redirect: header('Location: register.php?success'); The header file in the error: <!doctype html> <html> <?php include 'includes/head.php';?> <body> <?php include 'includes/header.php'?> <div id="container"> <?php include 'includes/aside.php'?> The reagester page: <?php include 'core/init.php'; logged_in_redirect(); include 'includes/overall/header.php'; if (empty($_POST) === false) { $requried_fields = array('username', 'password', 'password_again', 'first_name', 'email'); foreach($_POST as $key=>$value) { if(empty($value) && in_array($key, $requried_fields) === true) { $errors[] = 'Fields marked with an asterisk are requried.'; break 1; } } if (empty($errors) === true) { if (user_exists($_POST['username']) === true) { $errors[] = 'Sorry, the username \'' . $_POST['username'] . '\' is already taken.'; } if(preg_match("/\\s/", $_POST['username']) == true) { $errors[] = 'Your user name must cotain any spaces\.'; } if (strlen($_POST['password']) <6 || strlen($_POST['password']) >20) { $errors[] = 'Your password must be a least 6 character\'s in length and no more the 20.'; } 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 requird. Your privacy is inportant to us. We will not give or sell it to anyone. '; } if(email_exists($_POST['email']) === true){ $errors[] = 'Sorry, the email \'' . ($_POST['email']) . '\' is already taken.'; } } } ?> <h1>Register for the site.</h1> <?php if (isset($_GET['success']) && empty($_GET['success'])){ echo'You have sussessfully registered.'; } 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?success'); exit(); } else if (empty($errors) === false) { echo output_errors($errors); } ?> <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> Your E-Mail:<br> <input type="text" name="email"> </li> <li> <input type="submit" value="Register"> </li> </ul> </form> <?php } include 'includes/overall/footer.php';?> Quote Link to comment Share on other sites More sharing options...
grabenair Posted August 3, 2012 Author Report Share Posted August 3, 2012 I got this working, had to add <?php ob_start(); ?> to the top of the page and just after mt closing </html> tag Quote Link to comment Share on other sites More sharing options...
falkencreative Posted August 3, 2012 Report Share Posted August 3, 2012 You probably aren't getting errors on XAMPP because your error reporting there is set differently than the error reporting on the live server. If you are using header(), you can't have anything (text, blank space, anything) output to the browser before calling it otherwise you'll get that error. That's just the way that header() works. An alternative (other than simply not showing a message) would be to show a success message and then use Javascript in the page to redirect after X seconds, and avoid using header() entirely. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.