Måske noget i stil med:
<?php
$host = "
www.domain.dk";$port = 80;
$path = "/noget.php";
//you will need to setup an array of fields to post with
//then create the post string
$formdata = array ("user" => $user, "pass" => $pass, "login" => $login);
//build the post string
foreach($formdata AS $key => $val)
{
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
// strip off trailing ampersand
$poststring = substr($poststring, 0, -1);
$fp = fsockopen($host, $port, $errno, $errstr, $timeout = 30);
if(!$fp)
{
//error tell us
echo "$errstr ($errno)<br />\n";
}
else
{
//send the server request
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($poststring)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $poststring . "\r\n\r\n");
//loop through the response from the server
while(!feof($fp))
{
$output .= fgets($fp, 4096);
}
//close fp - we are done with it
fclose($fp);
}
?>
Og ellers er det næsten også bare at ændre GET til POST i dette eksempel:
Eksempel 1. fsockopen() Example
<?php
$fp = fsockopen("
www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host:
www.example.com\r\n"; $out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>