This is a discussion on Send headers and HTML all at once within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hy all, The variable $x contains all data to sent back to the user. Thus all headers and the HTML ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hy all,
The variable $x contains all data to sent back to the user. Thus all headers and the HTML for a HTML page in one variable. How do I send this back to the client browser? If I echo/print the data PHP creates its own set of headers and the headers in $x will be displayed in the browser window instead of sending it as headers. Is there any way to send the data in $x al at once so php does not create its own set of headers? Thanks in advance Rob |
|
|||
|
"Rob" <reply_@news_group.please> wrote:
>Is there any way to send the data in $x al at once so php does not create >its own set of headers? Well, PHP has a function called header(). But this won't work for you since headers and content isn't separate in your variable. Therefor you will have to use echo or print. PHP only creates headers itself if you output anything. You have to start the PHP code with <?php _in the first line_ of your file and then, before outputting anything else you have to do a echo $x. Sorry for my bad English, I hope it's still understandable. Regards, johannes |
|
|||
|
<?php
/* Each header should end with CRLF, represented as "\r\n". * The end of the headers is signified with an additional CRLF, * often referred to as a "blank line" between headers and document. * Make sure there are no blank lines before the opening <?php * tag, else the headers will be sent immediately. */ /* $x = your document and headers... */ $res = preg_split('(\r\n)', $x); $headers_done = false; for($i = 0; $i < count($res); $i++) { if($res[$i] == "\r\n") { $headers_done = true; } if($headers_done) { print $res[$i]; } else { header($res[$i]); } } ?> |