[PHP] Getting a value back from POST (not the built-in return)

2003-01-28 Thread Paul
Using a fairly simple fsockopen and POST I'm sending form data to a script which 
populates fields in a database. Everything works fine, however I've been trying to 
figure out how to send a value set on the other machine (database) back through the 
open socket (note: not the return value usually retrieved by fgets($fp etc...) which 
is then available to the sending machine. Searching via 
Google hasn't given me an answer.

Is it possible? Can somebody help? Syntax would be very nice, I'm not a PHP guru.

TIA,
Paul

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




Re: [PHP] Getting a value back from POST (not the built-in return)

2003-01-28 Thread Chris Hayes
At 01:38 29-1-03, you wrote:

Using a fairly simple fsockopen and POST I'm sending form data to a script 
which populates fields in a database. Everything works fine, however I've 
been trying to figure out how to send a value set on the other machine 
(database) back through the open socket (note: not the return value 
usually retrieved by fgets($fp etc...) which is then available to the 
sending machine. Searching via
Google hasn't given me an answer.

Is it possible? Can somebody help? Syntax would be very nice, I'm not a 
PHP guru.
i never did use fsockopen, but reading a bit in the online user-annotated 
manual (http://www.php.net/manual/en/function.fsockopen.php) i found this 
link that may help you on the sending side:
http://www.faqts.com/knowledge_base/view.phtml/aid/12039/fid/51

On the receiving side, if we're talking POST, then you HAVE to be aware of 
the change in handling them since PHP 4.10, before this version you could 
just try to read the POST variable directly, e.g. Name went to $Name, or 
better $HTTP_POST_VARS['Name']. But since then it is recommended to read it 
through $_POST['Name']. The old way only works if you set register_globals 
on in the php.ini file, if i remember well.

Unfortunately for you i only have a Dutch link to explain this better.


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



Re: [PHP] Getting a value back from POST (not the built-in return)

2003-01-28 Thread Chris Shiflett
--- Paul [EMAIL PROTECTED] wrote:
 Using a fairly simple fsockopen and POST I'm sending
 form data to a script which populates fields in a
 database. Everything works fine, however I've been
 trying to figure out how to send a value set on the
 other machine (database) back through the open socket
 (note: not the return value usually retrieved by
 fgets($fp etc...) which is then available to the
 sending machine. Searching via Google hasn't given me
 an answer.
 
 Is it possible? Can somebody help? Syntax would be very
 nice, I'm not a PHP guru.

Anything that the receiving Web server outputs is sent back
to you just as it would be a Web browser. So, you can read
this data just as if from a file (which is why fsockopen is
so convenient). Thus, just echo whatever you want to send
back.

You make a statement that is very conflicting:

 I've been trying to figure out how to send a value set
 on the other machine (database) back through the open
 socket (note: not the return value usually retrieved
 by fgets($fp etc...)

So, you want to send data back through the open socket,
but you do not want read this data from the socket. I think
you have a misunderstanding here somewhere that will make
things difficult for you. What fgets() gives you *is* the
data sent from the remote server.

If you want to pass data back in a manageable way, you will
probably want to output XML, because that is easier and
more reliable to parse than HTML.

Chris

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




Re: [PHP] Getting a value back from POST (not the built-in return)

2003-01-28 Thread Paul
Okay, some clarification. I do indeed want to read what I get back from the socket. 
Using fgets($fp, 1024) on the sending side (where the socket is opened and the data 
sent) and return = $variable on the other end (oh yes, the variable has a value as of 
the return), all I ever get back is 'HTTP 1.1' exactly, or nothing at all in the 
return value. Can you fill me in on the syntax here? How would you write the fgets 
statement and how would you define and populate the return value on the other end?

Chris wrote:

--- Paul [EMAIL PROTECTED] wrote:

 Using a fairly simple fsockopen and POST I'm sending
 form data to a script which populates fields in a
 database. Everything works fine, however I've been
 trying to figure out how to send a value set on the
 other machine (database) back through the open socket
 (note: not the return value usually retrieved by
 fgets($fp etc...) which is then available to the
 sending machine. Searching via Google hasn't given me
 an answer.
 
 Is it possible? Can somebody help? Syntax would be very
 nice, I'm not a PHP guru.


Anything that the receiving Web server outputs is sent back
to you just as it would be a Web browser. So, you can read
this data just as if from a file (which is why fsockopen is
so convenient). Thus, just echo whatever you want to send
back.
You make a statement that is very conflicting:


 I've been trying to figure out how to send a value set
 on the other machine (database) back through the open
 socket (note: not the return value usually retrieved
 by fgets($fp etc...)


So, you want to send data back through the open socket,
but you do not want read this data from the socket. I think
you have a misunderstanding here somewhere that will make
things difficult for you. What fgets() gives you *is* the
data sent from the remote server.

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




Re: [PHP] Getting a value back from POST (not the built-in return)

2003-01-28 Thread Chris Shiflett
--- Paul [EMAIL PROTECTED] wrote:
 Can you fill me in on the syntax here? How would you
 write the fgets statement and how would you define
 and populate the return value on the other end?

Maybe this example will help. This searches PHP's site for
curl, outputting the HTTP content to the screen. When you
are making a socket connection like this, you get the whole
HTTP response, not just the content. This example uses an
explode() to separate headers from content, which isn't
very safe (if the content contains \r\n somewhere, it
screws up), but it will probably work for you:

base href=http://www.php.net/;

?
$content = php_post(www.php.net, /search.php,
lang=en_USpattern=curlshow=manual);
echo $content;

function php_post($host, $path, $data)
{
   $http_response=;

   $fp=fsockopen($host, 80);
   fputs($fp, POST $path HTTP/1.1\r\n);
   fputs($fp, Host: $host\r\n);
   fputs($fp, Content-Type:
application/x-www-form-urlencoded\r\n);
   fputs($fp, Content-Length:  . strlen($data).\r\n);
   fputs($fp, Connection: close\r\n\r\n);
   fputs($fp, $data);
   while(!feof($fp))
   {
  $http_response.=fgets($fp, 128);
   }
   fclose($fp);

   list($http_headers, $http_content) = explode(\r\n\r\n,
$http_response);

   # This only returns the content - modify if you want to
also return the headers
   return $http_content;
}
?

Chris

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