实际上,当socket通道打开时,我们传的COOKIE是正确的话,(截图运行的php代码来自上边,运行后返回的网页出现了我的用户名,说明对方网站已经承认我已经登录了)咱就可以干N多事情,比如刷帖,刷回复等,你们懂的,对吧?
好了上面还不够有说服力我们来看一个php socket实现图片上传
这个代码有两点要注意:
一是他是http的post 请求;
二是表单上传协议,
下的请求 串适合任何语言.
代码如下
<?php $remote_server = "jb51.net"; $boundary = "---------------------".substr(md5(rand(0,32000)),0,10); // Build the header $header = "POST /api.php?action=twupload HTTP/1.0rn"; $header .= "Host: {$remote_server}rn"; $header .= "Content-type: multipart/form-data, boundary=$boundaryrn"; /* // attach post vars foreach($_POST AS $index => $value){ $data .="--$boundaryrn"; $data .= "Content-Disposition: form-data;.$index.""rn"; $data .= "rn".$value."rn"; $data .="--$boundaryrn"; } */ $file_name = "aaa.jpg"; $content_type = "image/jpg"; $data = ''; // and attach the file $data .= "--$boundaryrn"; $content_file = file_get_contents('aaa.jpg'); $data .="Content-Disposition: form-data;; filename="$file_name"rn"; $data .= "Content-Type: $content_typernrn"; $data .= "".$content_file."rn"; $data .="--$boundary--rn"; $header .= "Content-length: " . strlen($data) . "rnrn"; // Open the connection $fp = fsockopen($remote_server, 80); // then just fputs($fp, $header.$data); // reader while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp);