|
Open Socket
I have the following function that is supposed to connect to a socket and then return a pipe (|) delimitated string.
The problem is that it is returning nothing, nada, zero, zilch.
I have put the function below. This is my first time using the socket. Thanks for you help.
php Code:
Original
- php Code |
|
|
|
<?php function authorize($host, $usepath, $postdata = "") { # open socket to filehandle $fp = pfsockopen($host, 443, & $errno, & $errstr, 120); //pfsockopen(string hostname, int port, int errno, string errstr, int timeout) # user-agent name $ua = "yourUserAgent/1.0"; if( !$fp ) { print "$errstr ($errno)<br>n"; } else { fputs($fp, "POST $usepath HTTP/1.0n" , 1); fputs($fp, "User-Agent: ". $ua. "n" , 1); fputs($fp, "Accept: */*n" , 1); fputs($fp, "Accept: image/gifn" , 1); fputs($fp, "Accept: image/x-xbitmapn" , 1); fputs($fp, "Accept: image/jpegn" , 1); $strlength = strlen($postdata); // print $strlength; fputs($fp, "Content-type: application/x-www-form-urlencodedn" , 1); fputs($fp, "Content-length: ". $strlength. "nn" , 1); fputs($fp, $postdata. "n" , 1); $output = ""; { $output .= fgets($fp, 1024); } } return $output; } ?>
|