Try this sample code.
// Format of $authorization is username:password (for password protected directories)
// Code can be easily modified to add input parameters for User-Agent, Referer, Cookie, Accept-Encoding or other required headers
function HTTPPost($host, $path, $dataToSend, $port = 80, $authorization = "")
{
if(!($fp = fsockopen($host, $port)))
{
return "<b>From HTTPPost()</b><br>\n<b>Error:</b> Error opening network socket.<br>\n";
}
socket_set_blocking($fp, TRUE);
fwrite($fp, "POST $path HTTP/1.0\r\n");
if($authorization != "") fwrite($fp, "Authorization: Basic " . base64_encode($authorization) . "\r\n");
fwrite($fp, "Host: $host\r\n");
fwrite($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($fp, "Content-length: " . strlen($dataToSend) . "\r\n\r\n");
fwrite($fp, $dataToSend);
for($result = ""; !feof($fp); $result .= fread($fp, 1000000));
fclose($fp);
return $result;
}
function StripHTTPHeaders($text)
{
return substr($text, strpos($text, "\r\n\r\n") + 4);
}
$result = HTTPPost("www.myserver.com", "/path/myscript.php", "var1=value1&var2=value2");
$result = StripHTTPHeaders($result);
echo $result;