Send headers and HTML all at once

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-25-2004
Rob
 
Posts: n/a
Default Send headers and HTML all at once

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


Reply With Quote
  #2 (permalink)  
Old 10-25-2004
johannes m.r.
 
Posts: n/a
Default Re: Send headers and HTML all at once

"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
Reply With Quote
  #3 (permalink)  
Old 11-13-2004
Mike Gatny
 
Posts: n/a
Default Re: Send headers and HTML all at once

<?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]);
}
}
?>
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:15 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0