PHP + Socket sends HTTP requests to make Web site irrigation

Source: Internet
Author: User
In essence, implement the request line, header information, subject information of the assembly HTTP information, refer to it self-learning Network

The cookie information is very much related to the HTTP request header, and it is important to pass the HTTP request header information into the function.


01-msg.php

 SetHeader (' accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 '); $http->setheader (' Accept-encoding:gzip, deflate '); $http->setheader (' accept-language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 '); $ Http->setheader (' connection:keep-alive '); $http->setheader (' Cookie:hm_lvt_ c7849bb40e146a37d411700cb7696e46=1371132935,1371551596,1371552570; Cnzzdata1479=cnzz_eid%3d2070887527-1371133011-http%253a%252f%252fhome.verycd.com%26ntime%3d1371559611%26cnzz_a %3d27%26retime%3d1371559611556%26sin%3dhttp%253a%252f%252fwww.verycd.com%252fi%252f17907141%252f%26ltime% 3D1371559611556%26RTIME%3D1; __utma=248211998.1671623420.1371133015.1371557486.1371559612.4; __utmz=248211998.1371552579.2.2.utmcsr=verycd.com|utmccn= (referral) |utmcmd=referral|utmcct=/; hm_lpvt_c7849bb40e146a37d411700cb7696e46=1371554752; Post_action=repost; baidu_clb_refer=http%3a%2f%2fcwebmail.mail.163.com%2fjs5%2fread%2freadhtml.jsp%3fssid% 3di7zqecycxldkhplnxyxqm9sne5eph1drypvn26nzekk%253d%26mid%3d45%3a1tbilrfahfeFOLVTCAAASS%26COLOR%3D003399%26PREVENTSETREAD%3DON%26FONT%3D15; Uchome_loginuser=http%e5%8d%8f%e8%ae%ae; UCHOME__REFER=%2FSPACE.PHP%3FDO%3DPM%26FILTER%3DNEWPM; __utmc=248211998; sid=9a48b201fb4d176a7188ef2a3560789651eb4766; member_id=17822047; Member_name=http%e5%8d%8f%e8%ae%ae; mgroupid=93; PASS_HASH=E75F942862A5E927A2FAFFD2D2D582C9; Rememberme=false; uchome_auth=4128oujwyonkcxzvxm4sdrjcugsmt3l0r197pq%2bpdf8fcljsuinzkbxjg0hyupzsrk3xes2furn1ph2cefbnc1h0im7x5a; uchome_sendmail=1; Uchome_checkpm=1; __utmb=248211998.1.10.1371559612; Dcm=1 '); $http->setheader (' referer:http://home.verycd.com/cp.php?ac=pm '); $http->setheader (' User-Agent: mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) gecko/20100101 firefox/21.0 '); $msg = Array (' formhash ' = ' 4f23e777 ', ' message ' = ' I'm not watering, please release ', ' Pmsubmit ' = ' + ' true ', ' pmsubmit_btn ' = ' send ', ' refer ' and ' = ' http://home.verycd.com/space.php?do=pm&filter= PRIVATEPM ', ' username ' = ' http receive '); File_put_contents ('./res.html ', $http->post ($msg)); Echo ' OK ';

http.class.php

 Conn ($url);    $this->setheader (' Host: ' $this->url[' host '); }//This method is responsible for writing the request line protected function Setline ($method) {$this->line[0] = $method. ' ' . $this->url[' path ']. '? '. $this->url[' query '. ' '.    $this->version;     }//This method is responsible for writing header information public function SetHeader ($headerline) {$this->header[] = $headerline;    }//This method is responsible for writing the principal information protected function Setbody ($body) {$this->body[] = http_build_query ($body);        }//Connection URL public Function conn ($url) {$this->url = Parse_url ($url);        Determine the port if (!isset ($this->url[' Port ')) {$this->url[' port '] = 80;        }//Judge query if (!isset ($this->url[' query ')) {$this->url[' query '] = ';    } $this->fh = Fsockopen ($this->url[' host '), $this->url[' Port ', $this->errno, $this->errstr,3);        }//construct data for GET request public function get () {$this->setline (' get '); $this->requesT ();    return $this->response;        }//Construct data Public function post for post query ($body = Array ()) {$this->setline (' post ');                Design Content-type $this->setheader (' content-type:application/x-www-form-urlencoded ');        Design the main information, the place is different than get $this->setbody ($body);        Calculate content-length $this->setheader (' content-length: '. strlen ($this->body[0]));        $this->request ();    return $this->response; }//Really requests public Function request () {//To put the request line, header information, entity information in an array for easy splicing $req = Array_merge ($this->line,        $this->header,array ("), $this->body,array ("));        Print_r ($req);         $req = Implode (Self::crlf, $req); Echo $req;        Exit                Fwrite ($this->fh, $req);        while (!feof ($this->fh)) {$this->response. = fread ($this->fh,1024); } $this->close (); Close Connection}//close connection Public function close () {fclose ($this-&GT;FH); }}/* $url = ' http://news.163.com/13/0613/09/9187CJ4C00014JB6.html '; $http = new http ($url); Echo $http->get (); *//* Set_time_limit (0); $url = ' http://liangyue.net.cn/0523/? ';    for ($i =1; $i <100; $i + +) {$str = Str_shuffle (' abcdefghijklmnopqrst0776656 ');    $tit = substr ($str, 0,5);    $con = substr ($str, 6,8);    $http = new http ($url);    $http->post (' tit ' = ' + $tit, ' con ' + $con, ' submit ' + ' message ')); echo $tit, '-----------', $con, '
'; Usleep (2000);} */
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.