<?php
function newreq($req, &$session, $host='www.vulgarisation-informatique.com', $port=80, $re=true){
$sock=fsockopen($host, $port) or die('no connection');
fputs($sock, $req);
$result='';
if ($re){
while ($a=fgets($sock)){
$result.=$a;
}
if (false!==($a=strpos($result, 'Set-Cookie'))){
$a=substr($result, $a+strlen('set-Cookie: '));
$a=substr($a, 0, strpos($a, ';'));
$session.='
Cookie: '.$a;
}
return $result;
}
}
function post($host, $page, $post){
$session='';
$result=newreq('POST '.$page.' HTTP/1.1'."\r\n".
'Host: '.$host."\r\n".
'Content-Type: application/x-www-form-urlencoded'."\r\n".
'Content-Length: '.strlen($post)."\r\n\r\n".
$post."\r\n\r\n"
, $session, $host, 80, false);
return $result;
}
?>