Bhupendra Rathore
asked on
Warning: Cannot modify header information - headers already sent by (output started at /home/w3org/public_html/age/index.php:79) in /home/w3org/public_html/age/index.php on line 133
How can i solve this error :S
below is my index.php
and the line of the function 79 and 133 is-
index.php
below is my index.php
and the line of the function 79 and 133 is-
index.php
As an alternative to doing ob_start() which is not really what you want to be doing here you should be doing all your routing logic at the top of your page. In other words
What you have done is put your routing in the middle of your output which is not good practice. Routing happens before you start rendering the view.
<?php
if(isset($_POST['submit'])) {
$day=isset($_POST['day']) ? $_POST['day'] : false;
$month=isset($_POST['month']) ? $_POST['month'] : false;
$year=isset($_POST['year']) ? $_POST['year'] : false;
$age = (date("md", date("u", mktime(0, 0, 0, $day, $month, $year))) > date("md") ? ((date("Y")-$year)-1):(date("Y")-$year));
if($age > 21) {
header('Location: http://www.runningprofiles.com/error.php');
}
// Now you can put the rest of your logic here.
?>
What you have done is put your routing in the middle of your output which is not good practice. Routing happens before you start rendering the view.
Turn on output buffering
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
A header requires to be sent first, no output is allowed in advance.
What you could do is use output buffering, start your script with a php section even before the doctype:
Open in new window
Then in case you decide you want to send a Location header instead of the page, you do
Open in new window
And at the end of the script, for the normal case of no Location header output the buffer withOpen in new window
Bye, Olaf.