<?php
// ------------------------------------------------------------------------- //
// Une fonction qui utilise les sockets pour simuler une requête POST. //
// ------------------------------------------------------------------------- //
// Auteur: Christian Rishøj //
// Email: chrris@mail.dk //
// Web: //
// ------------------------------------------------------------------------- //
function httpPostRequest($host, $path, $arrPostvars, $port=80, $referer="")
{
$arrEncodedPairs = array();
$res = "";
foreach ($arrPostvars as $var => $value)
$arrEncodedPairs[] = rawurlencode($var)."=".rawurlencode($value);
$postData = implode("&", $arrEncodedPairs);
$request = "POST $path HTTP/1.1\n".
"Host: $host\n".
(($referer) ? "Referer: $referer\n" : "").
"Content-type: application/x-www-form-urlencoded\n".
"Content-length: ".strlen($postData)."\n".
"Connection: close\n\n".
$postData."\n";
// Some debug for you my friend :)
print("<pre>Request:\n".htmlentities($request)."</pre>");
if ($fp = fsockopen($host, $port))
{
if (fputs($fp, $request))
{
while(! feof($fp))
{
$res .= fgets($fp, 128);
}
fclose($fp);
return $res;
}
}
}
?>