----- Original Message -----
From: "Kevin Stone" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, June 16, 2003 4:02 PM
Subject: Re: [PHP] How to avoid Socket Post output?


>
> ----- Original Message -----
> From: "David Nicholson" <[EMAIL PROTECTED]>
> To: "Kevin Stone" <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Monday, June 16, 2003 3:22 PM
> Subject: Re: [PHP] How to avoid Socket Post output?
>
>
> > Hello,
> >
> >
> > This is a reply to an e-mail that you wrote on Mon, 16 Jun 2003 at
22:00,
> > lines prefixed by '>' were originally written by you.
> >
> > > Oh wait..  unless that output is required somehow.  I removed the echo
> > > statement now my request isn't being replied to by the database
> > > script.
> >
> > For a quick fix, change:
> >   echo fgets($fp, 128);
> > to:
> >   fgets($fp, 128);
> >
> > All the best,
> >
> > David.
>
>
> Yes but when I fail to output the socket file the request is no longer
> recieved.  No data is recorded in the POST array.  Let me explain once
more
> what I'm doing..
>
> 1) Initiate Script-A through the browser.
> 2) Script-A opens a socket connection to Script-B and posts a request.
> 3) Script-B produces a formated data string based on the requst.
> 4)  Script-B then opens a socket connection to Script-A and posts the
data.
>
> It should be seamless and it works for the most part.  But the thing is it
> outputs this generic server info which you can see in this working
example..
>
> http://www.helpelf.com/test.php
>
> You'll notice in the example that this server info.. I don't know what it
is
> becuase this is the first time I've done anything like this.. gets
outputed
> along with the request.  I can't NOT (double negative) output the request
> file becuase it contains the headers and data which make it all work.  At
> least that is what I realized a few minutes ago when I said ACK then Oh
(see
> two posts below).  :-)
>
> Now I'm looking for a way to avoid that server info output, without
> compromizing the functionality of the method,  if it is possible to do so.
>
> - Kevin

After brainstorming and experimenting for about an hour I found that I was
able to get by with a dirty hack.  I do an ereg match for each line that
comprises the server info being outputed.  These lines are not required for
the request to work so if the output matches one of the values in the
'skipit' array I ignore it, and if there are no matches then I assume it's a
required header and I output it.  Again I'm working off of very little
knowlege about how all of this actually works so I'm sure there's got to be
a real solution to this.  But for now at least the request works 100%
invisibly between these two servers and I am able to accomplish what I set
out to do.

Thanks for everybody's suggestions.  Here is the modified function...

# ===============================================================
# PostToHost($host, $path, $data_to_send)
# $host = valid domain (ie. http://www.asiostudio.com)
# $path = relative URL (ie. /myfile.php)
# $data_to_send = urlencoded key/val string (ie.
"key=val&key2=val2&key3=val3")
# ===============================================================
function PostToHost($host, $path, $data_to_send)
{
 $fp = fsockopen($host,80);
 fputs($fp, "POST $path HTTP/1.0\n");
 fputs($fp, "Host: $host\n");
 fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
 fputs($fp, "Content-length: " . strlen($data_to_send) . "\n");
 fputs($fp, "Connection: close\n\n");
 fputs($fp, $data_to_send);
 while(!feof($fp))
 {
  $str = fgets($fp, 128);

  $skpit = array(
  "HTTP/1.1 200 OK",
  "Date:",
  "Server:",
  "X-Powered-By:",
  "Connection:",
  "Content-Type:",
  "enSSL");

  $out = true;
  for($i=0; $i<count($skipit); $i++)
  {
   if(eregi($skpit[$i], $str))
    $out = false;
  }

  if ($out == true)
   echo $str;
 }
 fclose($fp);
}


- Kevin



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to