i am trying to write a script that can handle http requests and output them ... so far its kinda working ... but i am having problems with the post method! here is the code i hope someone can help me understand where i am mistaken:
<?php
function fsget($_url, $_port, $_timeout, $_do){
$out="";
$fp = fsockopen($_url, $_port, $_errno, $_errstr, $_timeout);
if (!$fp){
echo "$errstr ($errno) <br>\n";
} else {
fwrite($fp, $_do);
while (!feof($fp)){
$out .= fgets($fp);
}
fclose($fp);
}
return $out;
}
$in="";
$in = "GET / HTTP/1.1\r\n";
$in .= "Accept: */*\r\n";
$in .= "Accept-Language: bg\r\n";
$in .= "Accept-Encoding: gzip, deflate\r\n";
$in .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; brip1; .NET CLR 1.1.4322)\r\n";
$in .= "Connection: Keep-Alive\r\n";
$in .= "Content-Length: " . strlen($in) . "\r\n\r\n";
$out = '';
echo fsget( <somehost> , 80, 30, $in);
$in="";
$in = "POST /login.php HTTP/1.1\r\n";
$in .= "Accept: */*\r\n";
$in .= "Accept-Language: bg\r\n";
$in .= "Content-Type: application/x-www-form-urlencoded\r\n";
$in .= "Accept-Encoding: gzip, deflate\r\n";
$in .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; brip1; .NET CLR 1.1.4322)\r\n";
$in .= "Connection: Keep-Alive\r\n";
$in .= "Cache-Control: no-cache\r\n\r\n";
$in .= "username=test&password=test&Submit=%C2%EB%E5%E7\r\n";
$in .= "Content-Length: " . strlen($in) . "\r\n\r\n";
$out = '';
echo fsget( <somehost> , 80, 30, $in);
?>
this code gets the main page of a host and outputs it
and then it posts some info on the login.php page...
only the first part of the code works ... the second one doesnt work i only get a header reply from the server nothing else...
HELP!