riquez wrote:
>Here is a fsockopen() script I'm trying out.
>I've got about 10 similar scripts but i can't get any of them to work?
>
>This one just displays a blank page - it does not "move" the brower to the
>next page as a
>regular POST would do.
>
>What am I missing here?
>
>cheers,
>Riquez
>
><?php
>// test1.php
>
>$host = "127.0.0.1";
>$port = 80;
>$postdata = "field1=value1&field2=value2&field3=value3";
>if ($sp = fsockopen($host, $port)) {
> fputs($sp,"POST /test2.php HTTP/1.0\r\n");
> fputs($sp,"Host: $host\r\n");
> fputs($sp,"Content-type: application/x-www-form-urlencoded\r\n");
> fputs($sp,"Content-length: ".strlen($postdata)."\r\n");
> fputs($sp,"Connection: close\r\n\r\n");
> fputs($sp,$postdata);
> fclose($sp);
>}
>
>
Hi Riguez,
Look up the PHP documentation for fsockopen
(http://be2.php.net/fsockopen). There's an example there with a GET
request, but the principle for POST is the same: after you send the
request plus header, you have to read the response and display it.
Your example worked on my configuration by adding
while (! feof($sp))
{
print fgets($sp, 128);
}
before the fclose.
The only thing is; you also get the response header back (the actual
contents starts with "Hi Carl"):
HTTP/1.1 200 OK Date: Fri, 29 Apr 2005 21:09:28 GMT Server:
Apache/1.3.33 (Win32) PHP/4.3.10 X-Powered-By: PHP/4.3.10 Connection:
close Transfer-Encoding: chunked Content-Type: text/html 8A Hi Carl. You
are 38 years old. 0
I don't know how to make your browser take this header into account
when displaying the rest of the message. Would appreciate if somebody
could fill in the blanks here.
cheers,
Carl
Community email addresses:
Post message: [email protected]
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php-list/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/