You are here: Re: [PHP] How to suppress HTTP headers? « PHP « IT news, forums, messages
Re: [PHP] How to suppress HTTP headers?

Posted by tg-php on 08/16/05 20:31

hah.. I should have mentioned this as well, but my brain is absorbed in... sockets... and xml.. and sending headers manually via fputs.. nothing relative to this discussion at all.. hah..

<?php

$_XML_DATA = "<xmlGoesHere></xmlGoesHere>\r\n";

$_FULL_XML_REQUEST = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
$_FULL_XML_REQUEST .= "<!DOCTYPE REQUEST_GROUP SYSTEM \"SomeXMLdtd.dtd\">\r\n";
$_FULL_XML_REQUEST .= $_XML_DATA;

$_XML_REQUEST_HEADER = "POST /path/to/script.php HTTP/1.1\r\n";
$_XML_REQUEST_HEADER .= "Host: my.server.com\r\n";
$_XML_REQUEST_HEADER .= "Content-type: application/x-www-form-urlencoded\r\n";
$_XML_REQUEST_HEADER .= "Content-length: " . strlen($_FULL_XML_REQUEST) . "\r\n";
$_XML_REQUEST_HEADER .= "Connection: close\r\n\r\n";

$fp = fsockopen("my.server.com", 80, &$_FSOCK_ERR_NUMBER, &$_FSOCK_ERR_MESSAGE, 100);
~
if(!$fp){
exit("Failed to open socket...");
}

if (fputs($fp, $_XML_REQUEST_HEADER . $_FULL_XML_REQUEST) === FALSE) {
exit("Failed to send request...");
}

while(!feof($fp)){
~
// "@" error suppression used on fgets() due to bug in PHP that reports the following waring:
// Warning: fgets(): SSL: fatal protocol error in /var/www/secure/dev2/panda/DevTools/LandsafeTest/index.php on line XXXX
// No good solution found online, most people adjust their error reporting to ignore warnings (sloppy!)
$tmp = @fgets($fp, 4096);

$_XML_RESPONSE .= $tmp;
}
echo "<pre>\n";
echo $_XML_RESPONSE;

fclose($fp);
?>


= = = Original message = = =

Or use sockets...

http://us3.php.net/manual/en/function.fsockopen.php

Just don't send any HTTP headers.


kgt


tg-php@gryffyndevelopment.com wrote:

>BTW: I made a mistake last time. Apparently with CLI there are headers. You can use "php -q" to suppress headers when using PHP via CLI. Odd. Not sure I had to do that when I wrote a few CLI scripts before. Oh well, something to play with another day (don't have time to check it right now).
>
>So another thing I may be wrong on.. but a thought.. If you use the header() command, does it prevent the web server from generating it's own headers?
>
>That is, if you send out "<html><body>Something</body></html" does the web server automatically generate the headers but if you use header() it uses what PHP generates rather than it's own?
>
>If so.. can you just do:
>header();
>
>With nothing in it to suppress headers?
>
>Or can you do something like:
>
>header("<xml>stuff</xml>");
>
>?
>
>Just thinking out loud since nobody else has responded yet :)
>
>-TG
>
>= = = Original message = = =
>
>I knew my description was a bit mangled; I was trying to keep it short.
>Sorry. Take two:
>
>A "remote server" is sending event records to "my server" using HTTP POST
>requests to http://my.server.com/storeit.php, let's say. The remote server
>expects acknowledgement by way of a response to its request. My script
>("storeit.php") must respond like it would any other page request over HTTP;
>it simply uses echo/print to produce a response.
>
>This would work fine EXCEPT that the remote server is *badly* written. Its
>flaw? The HTTP headers included in my response trip it up. For some reason,
>it expects just the *contents* of the response, without headers.
>
>Here's a mock up of the current situation:
>
> --->Received from remote server
> HTTP/1.0 storeit.php POST
> Content-Type: text/xml
> Content-Length: 35
> Host: 11.11.11.11
>
> <DATA>
> <KEY>value</KEY>
> </DATA>
>
> <--- Reply sent to remote server
> HTTP/1.0 200 OK
> Content-Type: text/xml
> Content-Length: 34
> Host: 22.22.22.22
>
> <ACK>
> <ERROR>0</ERROR>
> </ACK>
>
>
>What the reply needs to look like is:
>
> <--- Reply sent to remote server
> <ACK>
> <ERROR>0</ERROR>
> </ACK>
>
>
>No headers.
>
>-----Original Message-----
>From: tg-php@gryffyndevelopment.com [mailto:tg-php@gryffyndevelopment.com]
>Sent: Tuesday, August 16, 2005 11:00 AM
>To: php-general@lists.php.net
>Cc: thomascapote@onlinenetworks.com
>Subject: Re: [PHP] How to suppress HTTP headers?
>
>So their page POSTs to a PHP page that you've created? I'm not seeing where
>headers come into play there, they're on output, not input. Maybe I just
>stayed up too late last night, but I'm having trouble wrapping my brain
>around the problem.
>
>One thing I did notice was you mentioned switches for CGI vs CLI SAPI. I
>expect that there wouldn't be a switch for CLI because no headers are needed
>when using PHP command line, therefore nothing to turn off. Again, maybe
>I'm misunderstanding the situation but thought I'd throw that thought in the
>ring.
>
>Maybe you can describe the interaction between the system you can't control
>and your PHP scripts better. Walk us through it step by step.
>
>-TG
>
>= = = Original message = = =
>
>I am coding a PHP page to deal with a badly implemented automated status
>update script on a remote server (that I do not control) which fails if my
>response to it's POST request has HTTP headers. Go figure. So the question
>is "How do I NOT send HTTP headers in my response?" or "How can my script
>suppress headers completely?" Whatever the solution, it should affect only
>this page/script.
>
>In chapter 43, the PHP Manual states: "Though the CGI SAPI provides a way to
>suppress HTTP headers, there's no equivalent switch to enable them in the
>CLI SAPI." How would one suppress HTTP headers, as noted above, in the CGI
>SAPI for a particular page on my site?
>
>Somebody, please help.
>--TC.


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация