Re: css/header problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Martin,

put following lines in header file, & first line of file
<?php
ob_start();
?>
and check is there is an blank space before and after "<?php" remove the spaces.



--- In php-objects@xxxxxxxxxxxxxxx, "Martin" <martin@...> wrote:

>
> Hi,
> 
> I have a program that works very well on my machine (Win7 apache 2.2 php 5.3.2) As soon as I copied it to the godaddy hostin account I got the "header already sent error" I made a compare between the 2 files and they came up identical the code - even stripped down to the following still produced the error
> 
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
> <html><script type="text/javascript" src="myjs.js"></script>
> <head><LINK rel="stylesheet" href="mystyle.css" type="text/css"></head>
> <?php
>     session_start();
>     echo '<body><div class="div1">Hello world</div></body>';
> ?>
> 
> I subsequently changed it to
> 
> <?php
>     session_start();
>     echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">';
>     $h = '<script type ="text/javascript">function loadjscssfile(filename, filetype){
>  if (filetype=="js"){ //if filename is a external JavaScript file
>   var fileref=document.createElement("script")
>   fileref.setAttribute("type","text/javascript")
>   fileref.setAttribute("src", filename)
>  }
>  else if (filetype=="css"){ //if filename is an external CSS file
>   var fileref=document.createElement("link")
>   fileref.setAttribute("rel", "stylesheet")
>   fileref.setAttribute("type", "text/css")
>   fileref.setAttribute("href", filename)
>  }
>  if (typeof fileref!="undefined")
>   document.getElementsByTagName("head")[0].appendChild(fileref)
> }</script>';
>     echo $h;
>       $h = '<script type ="text/javascript">loadjscssfile("myjs.js", "js");loadjscssfile("mystyle.css","css");</script>';
>         echo $h;
>     echo '<html>';
>     echo '<body><div class="div1">Hello world</div></body>';
> ... some more code here ...
> ?>
> 
> This got rid of the "header already sent problem but now the program works but without any of the of the styles applied. The routines in the myjs.js all work quite nicely. but why not the style. All the session stuff seems to work just as expected too.
> 
> except the part
> 
> 
>         if (!isset($_SERVER['PHP_AUTH_USER']))
>         {
>             $session_id = $_SESSION['session_id'];
>             header('WWW-Authenticate: Basic realm="My Program ' . $session_id .
>                 '"');
>             header('HTTP/1.0 401 Unauthorized');
>             echo 'You have to enter a valid user name and Password - Not logged in';
>             exit;
>         }
>  
> that again sends the header already sent error. I could write another password entry program but I'd rather fix the underlying program
> 
> If I look at the webpage in IE (by hitting F12) all the HTML code looks exactly like it is supposed to. 
> 
> Any ideas?
>



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux