tencent-模擬請求頭

最近...不多說,說多了都是淚,直接上問題和答案:

不使用CURL函數分別寫出client.phpserver.php兩個文件內容.
client.php模擬瀏覽器客戶端向server.php發送如下HTTP數據包.
server.php向client.php輸出md5(username+password)後的結果
POST http://localhost/server.php HTTP/1.1
Accept: image/jpeg, image/gif, image/pjpeg, */*
User-Agent: Mozilla/4.0
Content-Type: application/x-www-form-urlencoded
Host: localhost
Content-Length: 34
Connection: Keep-Alive
Cookie: HOSUPPORT=1; UBI=fi_Pnc;
username=a&password=c&action=login

//假設host:localhost
//Client.php文件內容爲:
$url = "http://localhost/server.php";
$fp = fsockopen ( "localhost", 80, $errno, $errstr, 3 );
$head = "POST /server.php HTTP/1.0\r\n";
$head .= "Accept: image/jpeg, image/gif, image/pjpeg, */*\r\n";
$head .= "User-Agent: Mozilla/4.0\r\n";
$head .= "Content-type: application/x-www-form-urlencoded\r\n";
$head .= "Host: localhost\r\n";
$head .= "Content-Length: 34\r\n";
$head .= "Connection: Keep-Alive\r\n";
$head .= "Cookie: HOSUPPORT=1; UBI=fi_Pnc;\r\n";
$head .= "\r\n";
 
$head .= trim ( "username=a&password=c&action=login" );
$write = fputs ( $fp, $head );
fgets ( $fp );
while ( ! feof ( $fp ) ) {
$line = fgets ( $fp );
echo $line . "<br>";
}
 
//Server.php內容爲:
echo md5($_POST['username'].$_POST['password']);












 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章