[PHP] How to avoid Socket Post output?

2003-06-16 Thread Kevin Stone
Hello list,

I'm attempting to use the PostToHost() function to send a request to a
remote script.  The purpose for this is to request and retrieve information
from a remote database without the need for messy HTTP  HTML methods.   I
realize that I could use an HTML form, put the data in hidden fields, and
send the request that way, but then I would have to redirect back from the
master script recording an unwanted page in the 'Back Button' history.  I'd
like to avoid that so I'm investigating methods of POST'ing through a manual
socket connection.

Here is that PostToHost() function..

/*
 PostToHost($host, $path, $data_to_send)
 $host; valid domain (ie. www.domain.com)
 $path; relative URL (ie. /myfile.php)
 $data_to_send; urlencoded key/val string (ie.
key=valkey2=val2key3=val3)
*/
function PostToHost($host, $path, $data_to_send)
{
 ob_end_flush();
 $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))
 {
  echo fgets($fp, 128);
 }
 fclose($fp);
}


It works great!  The only problem is I get output from the socket connection
and I don't know how to skip over it...

HTTP/1.1 200 OK
Date: Mon, 16 Jun 2003 20:10:36 GMT
Server: Apache/1.3.20 (Unix) ApacheJServ/1.1.2 PHP/4.2.3
FrontPage/5.0.2.2510 Rewrit/1.1a
X-Powered-By: PHP/4.2.3
Connection: close
Content-Type: text/html

I'm very much a newbie to all of this so you'll have to forgive me.  But I'm
wondering if there is anyway to avoid this output and have a completely
invisible manual socket POST?


Thanks,
Kevin Stone
[EMAIL PROTECTED]



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



Re: [PHP] How to avoid Socket Post output?

2003-06-16 Thread Kevin Stone
ACK!  NEVER MIND!

I'm just blind.  I didn't see the echo statement on the fgets() line.

Problem solved.

- Kevin

- Original Message -
From: Kevin Stone [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, June 16, 2003 2:46 PM
Subject: [PHP] How to avoid Socket Post output?


 Hello list,

 I'm attempting to use the PostToHost() function to send a request to a
 remote script.  The purpose for this is to request and retrieve
information
 from a remote database without the need for messy HTTP  HTML methods.   I
 realize that I could use an HTML form, put the data in hidden fields, and
 send the request that way, but then I would have to redirect back from the
 master script recording an unwanted page in the 'Back Button' history.
I'd
 like to avoid that so I'm investigating methods of POST'ing through a
manual
 socket connection.

 Here is that PostToHost() function..

 /*
  PostToHost($host, $path, $data_to_send)
  $host; valid domain (ie. www.domain.com)
  $path; relative URL (ie. /myfile.php)
  $data_to_send; urlencoded key/val string (ie.
 key=valkey2=val2key3=val3)
 */
 function PostToHost($host, $path, $data_to_send)
 {
  ob_end_flush();
  $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))
  {
   echo fgets($fp, 128);
  }
  fclose($fp);
 }


 It works great!  The only problem is I get output from the socket
connection
 and I don't know how to skip over it...

 HTTP/1.1 200 OK
 Date: Mon, 16 Jun 2003 20:10:36 GMT
 Server: Apache/1.3.20 (Unix) ApacheJServ/1.1.2 PHP/4.2.3
 FrontPage/5.0.2.2510 Rewrit/1.1a
 X-Powered-By: PHP/4.2.3
 Connection: close
 Content-Type: text/html

 I'm very much a newbie to all of this so you'll have to forgive me.  But
I'm
 wondering if there is anyway to avoid this output and have a completely
 invisible manual socket POST?


 Thanks,
 Kevin Stone
 [EMAIL PROTECTED]



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





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



Re: [PHP] How to avoid Socket Post output?

2003-06-16 Thread Kevin Stone
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.

Seems I desparately need a lesson in socket connections.  Does anyone know
of a good book or tutorial other than the manual that goes into this stuff
in depth?

- Kevin


- Original Message -
From: Kevin Stone [EMAIL PROTECTED]
To: Kevin Stone [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Monday, June 16, 2003 2:54 PM
Subject: Re: [PHP] How to avoid Socket Post output?


 ACK!  NEVER MIND!

 I'm just blind.  I didn't see the echo statement on the fgets() line.

 Problem solved.

 - Kevin

 - Original Message -
 From: Kevin Stone [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, June 16, 2003 2:46 PM
 Subject: [PHP] How to avoid Socket Post output?


  Hello list,
 
  I'm attempting to use the PostToHost() function to send a request to a
  remote script.  The purpose for this is to request and retrieve
 information
  from a remote database without the need for messy HTTP  HTML methods.
I
  realize that I could use an HTML form, put the data in hidden fields,
and
  send the request that way, but then I would have to redirect back from
the
  master script recording an unwanted page in the 'Back Button' history.
 I'd
  like to avoid that so I'm investigating methods of POST'ing through a
 manual
  socket connection.
 
  Here is that PostToHost() function..
 
  /*
   PostToHost($host, $path, $data_to_send)
   $host; valid domain (ie. www.domain.com)
   $path; relative URL (ie. /myfile.php)
   $data_to_send; urlencoded key/val string (ie.
  key=valkey2=val2key3=val3)
  */
  function PostToHost($host, $path, $data_to_send)
  {
   ob_end_flush();
   $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))
   {
echo fgets($fp, 128);
   }
   fclose($fp);
  }
 
 
  It works great!  The only problem is I get output from the socket
 connection
  and I don't know how to skip over it...
 
  HTTP/1.1 200 OK
  Date: Mon, 16 Jun 2003 20:10:36 GMT
  Server: Apache/1.3.20 (Unix) ApacheJServ/1.1.2 PHP/4.2.3
  FrontPage/5.0.2.2510 Rewrit/1.1a
  X-Powered-By: PHP/4.2.3
  Connection: close
  Content-Type: text/html
 
  I'm very much a newbie to all of this so you'll have to forgive me.  But
 I'm
  wondering if there is anyway to avoid this output and have a completely
  invisible manual socket POST?
 
 
  Thanks,
  Kevin Stone
  [EMAIL PROTECTED]
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 






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



Re: [PHP] How to avoid Socket Post output?

2003-06-16 Thread Lars Torben Wilson
On Mon, 2003-06-16 at 13:46, Kevin Stone wrote:
 Hello list,
 
 I'm attempting to use the PostToHost() function to send a request to a
 remote script.  The purpose for this is to request and retrieve information
 from a remote database without the need for messy HTTP  HTML methods.   I
 realize that I could use an HTML form, put the data in hidden fields, and
 send the request that way, but then I would have to redirect back from the
 master script recording an unwanted page in the 'Back Button' history.  I'd
 like to avoid that so I'm investigating methods of POST'ing through a manual
 socket connection.
 
 Here is that PostToHost() function..
 
 /*
  PostToHost($host, $path, $data_to_send)
  $host; valid domain (ie. www.domain.com)
  $path; relative URL (ie. /myfile.php)
  $data_to_send; urlencoded key/val string (ie.
 key=valkey2=val2key3=val3)
 */
 function PostToHost($host, $path, $data_to_send)
 {

Add here:

   $ret_string = '';

  ob_end_flush();
  $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))
  {
   echo fgets($fp, 128);

Replace the echo line above with:

  $ret_string .= fgets($fp, 2048) . \n;

  }
  fclose($fp);

Add here:

   return $ret_string;

 }
 
 
 It works great!  The only problem is I get output from the socket connection
 and I don't know how to skip over it...
 
 HTTP/1.1 200 OK
 Date: Mon, 16 Jun 2003 20:10:36 GMT
 Server: Apache/1.3.20 (Unix) ApacheJServ/1.1.2 PHP/4.2.3
 FrontPage/5.0.2.2510 Rewrit/1.1a
 X-Powered-By: PHP/4.2.3
 Connection: close
 Content-Type: text/html
 
 I'm very much a newbie to all of this so you'll have to forgive me.  But I'm
 wondering if there is anyway to avoid this output and have a completely
 invisible manual socket POST?

I'm assuming with the above that you want to get the returned text from 
the POST into a string for use instead of outputting it directly to the
browser; these changes should do that. Note: I haven't actually tested
it. :)


Good luck,

Torben


 Thanks,
 Kevin Stone
 [EMAIL PROTECTED]

-- 
 Torben Wilson [EMAIL PROTECTED]+1.604.709.0506
 http://www.thebuttlesschaps.com  http://www.inflatableeye.com
 http://www.hybrid17.com  http://www.themainonmain.com
 - Boycott Starbucks!  http://www.haidabuckscafe.com -




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



Re: [PHP] How to avoid Socket Post output?

2003-06-16 Thread David Nicholson
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.

--
phpmachine :: The quick and easy to use service providing you with
professionally developed PHP scripts :: http://www.phpmachine.com/

  Professional Web Development by David Nicholson
http://www.djnicholson.com/

QuizSender.com - How well do your friends actually know you?
 http://www.quizsender.com/
(developed entirley in PHP)

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



Re: [PHP] How to avoid Socket Post output?

2003-06-16 Thread Kevin Stone

- 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




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



Re: [PHP] How to avoid Socket Post output?

2003-06-16 Thread David Nicholson
Hello,


This is a reply to an e-mail that you wrote on Mon, 16 Jun 2003 at 23:03,
lines prefixed by '' were originally written by you.
 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.

In that case script B does not need to open a socket connection to
Script-A just have script B output the relevant data (e.g. using echo
statements) then adjust the function that you posted earlier so that all
the data sent back from the script (in response to your HTTP request) is
stored in a variable (a previous poster explained how to do this).  Then
split this data at a double new line, discard the first segment (this is
just the headers) and the next part will contain the output that you
require.

Hope this helps,

David.

--
phpmachine :: The quick and easy to use service providing you with
professionally developed PHP scripts :: http://www.phpmachine.com/

  Professional Web Development by David Nicholson
http://www.djnicholson.com/

QuizSender.com - How well do your friends actually know you?
 http://www.quizsender.com/
(developed entirely in PHP)

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



Re: [PHP] How to avoid Socket Post output?

2003-06-16 Thread Kevin Stone

- 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=valkey2=val2key3=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; $icount($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