Jump to content

Recommended Posts

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

 

 

  • 3 weeks later...

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.

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

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.