Using sockets?

From: Date: Thu, 26 Oct 2000 14:54:37 +0000
Subject: Using sockets?
Groups: php.general 
Request: Send a blank email to php-general+get-22143@lists.php.net to get a copy of this message
I want to send data using the POST method with direct socket access. First, let me qualify myself by telling you that I have never done direct socket access. I modified the code from the example in "Professional PHP Programming". There are three parts to my testing/learning example: 1) The function in the Class 2) The PHP script that uses the Class 3) The PHP script that is suppose to receive the POST data The data is not being passed to Test.PHP or at least my $msg variable is empty. Does someone have experience in passing data using the POST method? Many thanks.......... Todd /* The class function */ ////////// function http_fpost($host, $data, $path, $port = 80) { # has the user set $proxy_host? if(empty($this->proxy_host)) { # we access the server directly $conn_host = $host; $conn_port = $port; } else { # we use the proxy $conn_host = $this->proxy_host; $conn_port = $this->proxy_port; } # build the absolute URL $abs_url = "http://$host:$port$path"; # now we build our query $query = "POST $abs_url HTTP/1.0\r\n". "Host: $host:$port\r\n". "User-agent: PHP/class http 0.1\r\n". "\r\n$data\r\n". "\r\n\r\n\r\n"; # open a connection to the server $fp = fsockopen($conn_host, $conn_port); # if the connection failed, return false if($fp) { # send our query fputs($fp, $query); # discard the HTTP header while(trim(fgets($fp, 1024)) != ""); # return the active file pointer return $fp; } else { return false; exit; } } ////////// /* The PHP script using the class */ ////////// <?php include "http.class"; $http = new http; $fp = $http->http_fpost("209.204.172.137", "MESSAGE=Posting info", "/test/php/test.php"); if($fp) { fpassthru($fp); } else { print "Sorry, the server is not currently available"; exit; } ?> ////////// /* The "receiving script */ ////////// <HTML> <HEAD> <TITLE>Untitled Document</TITLE> </HEAD> <BODY BGCOLOR="#ffffff"> <? $msg = $HTTP_POST_VARS[MESSAGE]; echo("Msg: " . $msg . "<br>"); ?> This is a test script<br> </HTML> ////////// -- Todd Cary Ariste Software todd@aristesoftware.com

« previous php.general (#22143) next »