justin7410 Posted April 6, 2013 Share Posted April 6, 2013 Hey guys, I am currently trying to finalize my registration page, and i am have some issues with the header() function. i know there are certain rules like no html can be above the header. and what not but i am fairly new to this and can figure out why i am outputting an error. my code is : <?if (isset($_GET['success']) && empty($_GET['success'])) { echo '<h1> Thank you for your registration </h1>'; } else { if (empty($_POST) === false && empty($errors) === true ) { $register_data = array( 'email' => $_POST['register_email'], 'username' => $_POST['register_username'], 'password' => $_POST['password'], 'gender' => $_POST['gender'], 'month' => $_POST['month'], 'date' => $_POST['date'], 'year' => $_POST['year'], 'country' => $_POST['country'], ); user_register($register_data); header('Location: register.php?success'); exit(); } else if ( empty($errors) === false) { echo '<div class="register_errors">'; echo '<span style="color:red"><h3>'; echo output_errors($errors); echo '</h3></span>'; echo '</div>'; } } ?> All of the code works for me until i try to send send the message. The error i get is the following : Warning: Cannot modify header information - headers already sent by (output started at /home/justin/public_html/include/header.php:31) in /home/justin/public_html/register.php on line 67 it directs me to my header.php file <!DOCTYPE html> <div> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="author" content="#"> <meta name="keywords" content="#"> <meta name="description" content="#"> <meta name="robots" content="#"> <meta name="revisit-after" content="7 days"> <link href="css/style.css" rel="stylesheet" type="text/css"> <link href="css/normalize.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="jscript/sidebar.js"></script> <script type="text/javascript" src="jscript/mootools.js"></script> <body> <div class="top"> Any suggestions ? cant seem to figure this one out Quote Link to comment Share on other sites More sharing options...
trq Posted April 6, 2013 Share Posted April 6, 2013 The rule is "no output before a call to the header function. The error tells you where the output is coming from. Line 31 of header.php Quote Link to comment Share on other sites More sharing options...
rustygb Posted April 26, 2013 Share Posted April 26, 2013 Hello There, Even i am experiencing same problem. Is there any other options to use to redirect to another page. i have used http_redirect(url) but didn't help as page doesn't display any error. You will fetch some output and then only you will redirect then how cum its possible to put header on the top. Please help me in this. Quote Link to comment Share on other sites More sharing options...
PaperTiger Posted April 28, 2013 Share Posted April 28, 2013 If you want to use php to redirect to another page, you have to follow the "no output before the header" rule. Even a new line or some whitespace will cause the "headers already sent" error because it is output that has been sent to the buffer. Either : A) Get rid of the output before the header call. B) Clear the output buffer before the header call. [more info] C) Use javascript to do the redirect 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.