<?phpfunction getrequestcookie ($webHomePageUrl, $cookieFileName) { // Initialize a curl session $curl = curl_init (); $options = Array ( CURLOPT_URL => $WEBHOMEPAGEURL, // Set the requested url curlopt_httpget => 1, //to be requested in Get mode CURLOPT_COOKIEJAR => $cookieFileName, // Save cookie information to file after connection ends. curlopt_timeout => 300, //sets the maximum number of seconds that curl is allowed to execute. curlopt_returntransfer => true, //will Curl_exec () The information obtained is returned in the form of a file stream, which is not output directly. When curlopt_header => true //is enabled, the information for the header file is output as a data stream. ) curl_setopt_array ($curl, $options); $result = curl_exec ($curl); if ($result == = false) { echo ' curl error: ' . Curl_errno ($curl); } curl_close ($curl); return $result;} $webHomePageUrl = ' http://www.oldwebadmin.com '; $cookieFileName = dirname (__file__) . DIRECTORY_SEPARATOR . ' Cookie.log '; Getrequestcookie ($webHomePageUrl, $cookieFileName); Function simulatepostrequest ($requestUrl, $userAgent, $postData, $cookieFileName) { //Initialize a Curl session $curl = curl_init (); //curl_setopt set transfer options for Curl $options = array (curlopt_url => $REQUESTURL, curlopt_post => 1, CURLOPT_POSTFIELDS => $postData, curlopt_header => true, //the header file information as a data stream when enabled CURLOPT_COOKIEFILE => $cookieFileName, //contains the file name of the cookie data curlopt_returntransfer => true, //will Curl_exec () The information obtained is returned in the form of a file stream, which is not output directly. ) //for Curl Transfer session bulk Setup options curl_setopt_array ($ curl, $options); $result = curl_exec ($curl); if ($result === false) { echo ' Curl error: ' . curl_errno ($curl); } curl_close ($curl) ; return $result;} $loginUrl = ' Http://www.oldwebadmin.com/login '; $userAgentInfo = ' mozilla/5.0 (windows nt 6.2; wow64; rv:40.0) Gecko/20100101 firefox/40.0 '; $postData = array (' username ' => ' username ', ' password ' = > ' password '); $doLoginInfo = simulatepostrequest ($loginUrl, $userAgentInfo, $ postdata, $cookieFileName);class mythread extends thread { private $opInfoFile; public function __construct ($fileNames) { $parentDir = dirname (__file__) . directory _separator . ' Thtest ' . DIRECTORY_SEPARATOR; $this->opinfofile = $parentDir . $fileNames; } public function run () { $ useragentinfo = ' mozilla/5.0 (windows nt 6.2; wow64; rv:40.0) gecko/20100101 firefox/40.0 '; $cookieFileName = dirname (__file__) . directory_ separator . ' Cookie.log '; usleep (Ten); $oprate = ' http://www.oldwebadmin.com/op '; $opostData = array (' data1 ' => ' test1 ', ' data2 ' => ' test1 ', ' data3 ' => ' test2 '); $ Opinfo = simulatepostrequest ($oprate, $userAgentInfo, $opostData, $cookieFileName); file_put_contents ($this->opinfofile, serialize ($opInfo ); } $threadPool = array ();for ($i = 0; $i < 100; $i + +) { $threadPool [$i] = new mythread (' thtest '. $i. '. log '); $ threadpool[$i]->start ();}
This article is from my It career blog, so be sure to keep this source http://quietnight.blog.51cto.com/7163892/1691125
PHP Small Code----Curl Analog login and log in and repeated post data through multi-threaded submission