Rifts Posted March 19, 2010 Share Posted March 19, 2010 hey everyone. i'm getting this error: Warning: Cannot modify header information - headers already sent by i know its because the code is not the first line but there is no way for it to be on the first line because the code has this: if ($check == 1) { header("location: domainform.php"); } Else { header("location: payment.php"); } so is there anyway to redirect someone with php without useing header? Quote Link to comment https://forums.phpfreaks.com/topic/195758-godaddy-header-problem/ Share on other sites More sharing options...
Rifts Posted March 19, 2010 Author Share Posted March 19, 2010 well i figured it out if anyone else has this problem just add this ob_start(); if ($check == 1) { header("location: domainform.php"); } Else { header("location: payment.php"); } ob_flush(); Quote Link to comment https://forums.phpfreaks.com/topic/195758-godaddy-header-problem/#findComment-1028371 Share on other sites More sharing options...
trq Posted March 19, 2010 Share Posted March 19, 2010 That is a hack. You should fix your code so no output is sent prior to redirecting. Quote Link to comment https://forums.phpfreaks.com/topic/195758-godaddy-header-problem/#findComment-1028410 Share on other sites More sharing options...
Rifts Posted March 20, 2010 Author Share Posted March 20, 2010 how do i fix it Quote Link to comment https://forums.phpfreaks.com/topic/195758-godaddy-header-problem/#findComment-1028860 Share on other sites More sharing options...
DavidAM Posted March 20, 2010 Share Posted March 20, 2010 The error message does not mean that the header() function must be the first line of code. It just has to be executed before any output is sent (to the browser). Output is sent when you call echo, print() or other functions that send information. If an error occurs and error_reporting is on, errors are sent to the browser. Anything, ANYTHING including blank lines or spaces that are outside of the php tags (<?php ... ?> or <? ... ?>) is automatically sent to the browser. Check everything above the code that is calling the header() function. Also check all included files. One common cause is when there is a line-feed (or carriage-return) after the last closing tag "?>" in an included file. A common solution to this, is to just not include the closing tag in the included files. You'll have to decide for yourself whether that is a hack or not. Also make sure there is NOTHING BEFORE the first opening php tag. Quote Link to comment https://forums.phpfreaks.com/topic/195758-godaddy-header-problem/#findComment-1028862 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.