Author Topic: Warning: Cannot modify header information - headers already sent by (output star  (Read 391 times)

bebelie

  • New Member
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
Dear PHP HELP,

i am having the following error in my website www.flowersmanama.com please check the website:
Warning: Cannot modify header information - headers already sent by (output started at
i made many search but i wasn't able to solve it..
will you please guide me?

PHP Code: [Select]
<?php
header
("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.flowersmanama.com");
?> 


Code: [Select]
<?
session_start();
// Include MySQL class
require_once('inc/mysql.class.php');
// Include database connection
require_once('inc/global.inc.php');
// Include functions
require_once('inc/functions.inc.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
header
("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.flowersmanama.com");
?>

<title><? include("includes/title.php") ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en-us" />
<? include("includes/keywords.php") ?>
..........
.........
............

wilson382

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 649
  • Karma: 27
  • PHP Helper
    • View Profile
the problem might be on www.flowersmanama.com not your headers
If help you, Click the [+] Karma to thanks me

bebelie

  • New Member
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
what do you mean? so how can i found the error?

phphelp

  • Administrator
  • Senior Member
  • *****
  • Posts: 868
  • Karma: 3
    • View Profile
    • PHP Help forum
These two lines in your code not make sense:
Code: [Select]
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.flowersmanama.com");

First, you're outputting part of HTML page, and then suddenly making redirect.
If you want to redirect to another page, these two lines must be above any HTML code in your php script, like this:
PHP Code: [Select]
<?
header
("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.flowersmanama.com");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Are you experienced in PHP programming and willing to share your knowledge?
Join us at php help forum!

bebelie

  • New Member
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
When i put the code at the top of the file, the way you told me, the website is not opening:

The page isn't redirecting properly
     
     
     
     
     
       
       
          Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
       

       
       

  This problem can sometimes be caused by disabling or refusing to accept
    cookies.

any other suggestions?

Andrew

  • iPhone Application & Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 339
  • Karma: 9
  • PHP, MySQL, HTML, and CSS are my playground
    • View Profile
You seem to have resolved this issue? site checks out ok now. What was your solution?
You cannot solve a puzzle if you don't have all the pieces.
Please + my karma if I helped you. <-- over there under my picture.

bebelie

  • New Member
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
No it is not, i am still trying...
when you checked the website i removed the code...
still not solved..
i am trying to add the following code:

PHP Code: [Select]

<?php
    
function currentPageURL() {
    
$curpageURL 'http';
    if (
$_SERVER["HTTPS"] == "on") {$curpageURL.= "s";}
    
$curpageURL.= "://";
    if (
$_SERVER["SERVER_PORT"] != "80") {
    
$curpageURL.= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
    
$curpageURL.= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    return 
$curpageURL;
    }

    
$FullUrl currentPageURL();
    if (
$FullUrl "http://flowersmanama.com/")
        {
                
Header"HTTP/1.1 301 Moved Permanently" );
                
Header"Location: http://www.flowersmanama.com/" );
        }

?>

bebelie

  • New Member
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
IT IS WOKING NOW With the following code:

Code: [Select]

<?
session_start();
function currentPageURL() {
    $curpageURL = 'http';
    if ($_SERVER["HTTPS"] == "on") {$curpageURL.= "s";}
    $curpageURL.= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
    $curpageURL.= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
    $curpageURL.= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    return $curpageURL;
    }

    $FullUrl = currentPageURL();
    $url ="http://flowersmanama.com/";
    if ($FullUrl == $url)
        {
                Header( "HTTP/1.1 301 Moved Permanently" );
                Header( "Location: http://www.flowersmanama.com/" ); 
                               
        }


Andrew

  • iPhone Application & Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 339
  • Karma: 9
  • PHP, MySQL, HTML, and CSS are my playground
    • View Profile
I am confused what is the Old url/page and what is the new URL.

If I am reading this correctly your issuing a 301 error for that page then forwarding right back to that page. It cannot be Permanently moved and at the same url.
You cannot solve a puzzle if you don't have all the pieces.
Please + my karma if I helped you. <-- over there under my picture.

RaythXC

  • PHP Programmer & Web-Designer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 395
  • Karma: 10
  • Freelance PHP Programmer/Web-Designer
    • View Profile
    • Rayth.Info
That's what i'm reading as well. If you're just adding the www part, you can do that with .htaccess rather than a whole script
RaythXC - My Home Site
Note: most answers I give come from the php manual located at PHP.Net

Andrew

  • iPhone Application & Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 339
  • Karma: 9
  • PHP, MySQL, HTML, and CSS are my playground
    • View Profile
Please hit the solved button at the bottom of the page if you have a solution please.
You cannot solve a puzzle if you don't have all the pieces.
Please + my karma if I helped you. <-- over there under my picture.