Og koden er yderligere udbygget:
<?php
$user = "user1";
$pass = "pass2";
$login = "LOGIN";
$host = "
www.codebreaker.dk";$port = 80;
$path = "/exp/704739.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);
}
if (preg_match('/PHPSESSID=(.+?);/', $output, $regs))
{
$phpsessid = $regs[1];
}
echo "Session: " . $phpsessid . "\n";
flush();
$fp = fsockopen($host, $port, $errno, $errstr, $timeout = 30);
if (!$fp)
{
//error tell us
echo "$errstr ($errno)<br />\n";
}
else
{
fputs($fp, "GET $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Cookie: PHPSESSID=$phpsessid\r\n");
fputs($fp, "Connection: Close\r\n\r\n");
//loop through the response from the server
while (!feof($fp))
{
$output .= fgets($fp, 128);
}
fclose($fp);
}
echo '<pre>';
echo $output;
echo '</pre>';
?>