note 67395 modified in function.fsockopen by danbrown

From: Date: Mon, 18 May 2009 01:50:12 +0000
Subject: note 67395 modified in function.fsockopen by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155603@lists.php.net to get a copy of this message
Here is how to POST a form action to a SSL server's cgi and retrieve output with pfsockopen <?php $host = gethostbyaddr($_SERVER['REMOTE_ADDR']); # working vars $host = 'www.example.com'; $service_uri = '/cgi-bin/processACT'; $vars ='code=22&act=TEST'; # compose HTTP request header $header = "Host: $host\r\n"; $header .= "User-Agent: PHP Script\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: ".strlen($vars)."\r\n"; $header .= "Connection: close\r\n\r\n"; $fp = pfsockopen("ssl://".$host, 443, $errno, $errstr); if (!$fp) { echo "$errstr ($errno)<br/>\n"; echo $fp; } else { fputs($fp, "POST $service_uri HTTP/1.1\r\n"); fputs($fp, $header.$vars); fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?> --was-- Here is how to POST a form action to a SSL server's cgi and retrieve output with pfsockopen <?php $host = gethostbyaddr($_SERVER['REMOTE_ADDR']); # working vars $host = 'www.example.com'; $service_uri = '/cgi-bin/processACT'; $vars ='code=22&act=TEST'; # compose HTTP request header $header = "Host: $host\r\n"; $header .= "User-Agent: PHP Script\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: ".strlen($vars)."\r\n"; $header .= "Connection: close\r\n\r\n"; $fp = pfsockopen("ssl://".$host, 443, $errno, $errstr); if (!$fp) { echo "$errstr ($errno)<br/>\n"; echo $fp; } else { fputs($fp, "POST $service_uri HTTP/1.1\r\n"); fputs($fp, $header.$vars); fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?> http://php.net/manual/en/function.fsockopen.php

« previous php.notes (#155603) next »