This is a discussion on Send headers and HTML all at once within the PHP General 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 |
|
|||
|
<?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]); } } ?> |