PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/test/poster/_head.php

http://clover-mana.googlecode.com/
PHP | 197 lines | 162 code | 16 blank | 19 comment | 8 complexity | 236dacedb03d0eebca1a9a20bd3d3dcc MD5 | raw file
  1. <?php
  2. ini_set ("max_execution_time","3600");
  3. define( 'DS', DIRECTORY_SEPARATOR );
  4. define( 'WS', '/' );
  5. define( 'ROOTPATH', dirname(__FILE__) );
  6. $mcookies = "/cookie.txt";
  7. //$mcookies = "cookie.txt";
  8. $mcookies = "C:\\xampp\htdocs\\test/poster/cook.txt" ;
  9. define( 'COOKIES', $mcookies );
  10. session_start();
  11. function curl_postaction($url,$data,$proxy= '',$proxystatus = 'off'){
  12. $fp = fopen(COOKIES, "w");
  13. $login = curl_init();
  14. curl_setopt($login, CURLOPT_COOKIEJAR, COOKIES);
  15. curl_setopt($login, CURLOPT_COOKIEFILE, COOKIES);
  16. curl_setopt($login, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1");
  17. curl_setopt($login, CURLOPT_TIMEOUT, 40);
  18. curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
  19. if ($proxystatus == 'on') {
  20. curl_setopt($login, CURLOPT_SSL_VERIFYHOST, FALSE);
  21. curl_setopt($login, CURLOPT_HTTPPROXYTUNNEL, TRUE);
  22. curl_setopt($login, CURLOPT_PROXY, $proxy);
  23. }
  24. curl_setopt($login, CURLOPT_URL, $url);
  25. curl_setopt($login, CURLOPT_HEADER, TRUE);
  26. curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  27. curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
  28. curl_setopt($login, CURLOPT_POST, TRUE);
  29. curl_setopt($login, CURLOPT_POSTFIELDS, $data);
  30. ob_start(); // prevent any output
  31. return curl_exec ($login); // execute the curl command
  32. ob_end_clean(); // stop preventing output
  33. fclose($fp);
  34. curl_close ($login);
  35. unset($login);
  36. }
  37. function curl_grab_page($site,$proxy= '',$proxystatus = 'off'){
  38. $ch = curl_init();
  39. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  40. if ($proxystatus == 'on') {
  41. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  42. curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
  43. curl_setopt($ch, CURLOPT_PROXY, $proxy);
  44. }
  45. curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
  46. curl_setopt($ch, CURLOPT_URL, $site);
  47. ob_start(); // prevent any output
  48. return curl_exec ($ch); // execute the curl command
  49. ob_end_clean(); // stop preventing output
  50. curl_close ($ch);
  51. }
  52. function getUrl($url){
  53. $cookieFile = dirname(__FILE__).DIRECTORY_SEPARATOR.'cookie.txt';
  54. $curl = curl_init();
  55. // Set CURL cookie option
  56. curl_setopt($curl, CURLOPT_COOKIEJAR, $cookieFile);
  57. curl_setopt($curl, CURLOPT_COOKIEFILE, $cookieFile);
  58. curl_setopt($curl, CURLOPT_URL, $forumUrl);
  59. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  60. curl_setopt($curl, CURLOPT_HEADER, 0);
  61. return curl_exec($curl);
  62. }
  63. $myarr= array(
  64. 'base_url' => 'http://www.vietmanga.vn',
  65. 'topic_url' => 'http://www.vietmanga.vn/main-forum-2/aaa3333333333333-8/',
  66. 'topic_id' => 8,
  67. 'username' => 'Kai',
  68. 'password' => 'lovecomputer');
  69. //doPost4rum($myarr,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','bodyyyyyyyyyyyyyy&yyyyyyyyyyy^^yyyyyyyyyyyyyyyyyyyyyy');
  70. /*
  71. ham nay thuc thi tac vu dang nhap va post 1 bai den 1 topic nhat dinh
  72. thong so dau gom co:
  73. 1 mang thong tin dang nhap : base url:noi chua 4rum,topic url,topic id,u,p
  74. title
  75. post body
  76. */
  77. function doPost4rum($iarr = array(),$ptitle="",$pbody=""){
  78. //kiem tra xem dieu kien post co hop le hay khong
  79. if( empty($iarr) || (strlen($ptitle) < 10) || (strlen($pbody) < 10) ){
  80. return -1;
  81. }else{
  82. //login 4rum
  83. $postLogins = array(
  84. "vb_login_username={$iarr['username']}",
  85. "vb_login_password={$iarr['password']}",
  86. "securitytoken=guest",
  87. "do=login",
  88. "cookieuser=1"
  89. );
  90. $loginDatas = implode('&', $postLogins);
  91. curl_postaction($iarr['base_url'].'/login.php?do=login',$loginDatas,$proxy,$proxystatus);
  92. //get security token
  93. $html = curl_grab_page($iarr['topic_url'],$proxy,$proxystatus);
  94. $math = preg_match("/var\s?SECURITYTOKEN\s?=\s?\"(.*?)\"/ims", $html, $matches);
  95. //post data
  96. $postFields = array(
  97. "title"=>$ptitle,
  98. "message"=>$pbody,
  99. "do"=>"postreply",
  100. "securitytoken"=>"{$matches[1]}"
  101. );
  102. // $postDatas = implode('&', $postFields);
  103. // echo curl_postaction("http://localhost/test/checkpost.php",$postFields,$proxy,$proxystatus);
  104. $postUrl = $iarr['base_url']."/newreply.php?do=postreply&t=".$iarr['topic_id'];
  105. curl_postaction($postUrl,$postFields,$proxy,$proxystatus);
  106. }
  107. return 1;
  108. }
  109. /*
  110. send a header request only to a hosting.Return the code or -1 if cant send request
  111. */
  112. function checkHeader($siteUrl){
  113. ob_start();
  114. $ch = curl_init(); // create cURL handle (ch)
  115. if (!$ch) {
  116. die("Couldn't initialize a cURL handle");
  117. }
  118. // set some cURL options
  119. $ret = curl_setopt($ch, CURLOPT_URL, $siteUrl);
  120. $ret = curl_setopt($ch, CURLOPT_HEADER, 1);
  121. $ret = curl_setopt($ch, CURLOPT_NOBODY, 1);
  122. $ret = curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  123. $ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
  124. $ret = curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  125. // execute and get respond content since exec dunt return
  126. $ret = curl_exec($ch);
  127. $retrievedhtml = ob_get_contents();
  128. ob_end_clean();
  129. // echo $ret;
  130. if (empty($ret)) {
  131. // some kind of an error happened
  132. // echo(curl_error($ch));
  133. $math = preg_match('/^HTTP\/(.{4}?)(.*?)$/ism',$retrievedhtml,$match);
  134. return $match[2];
  135. curl_close($ch); // close cURL handler
  136. } else {
  137. $info = curl_getinfo($ch);
  138. curl_close($ch); // close cURL handler
  139. if (empty($info['http_code'])) {
  140. return -1;
  141. } else {
  142. // load the HTTP codes
  143. $http_codes = parse_ini_file("ser_code.ini");
  144. $myRetstr = $info['http_code'] . " " . $http_codes[$info['http_code']];
  145. return $myRetstr;
  146. }
  147. }
  148. }
  149. function readmyline($lines){
  150. $tmp = array();
  151. foreach($lines as $line){
  152. $tmplime = array();
  153. $myline = explode("|", $line);
  154. $tmplime['base_url'] = $myline[0];
  155. $tmplime['topic_url'] = $myline[1];
  156. $tmplime['topic_id'] = $myline[2];
  157. $tmplime['username'] = $myline[3];
  158. $tmplime['password'] = $myline[4];
  159. array_push($tmp,$tmplime);
  160. }
  161. return $tmp;
  162. }
  163. function unique_url($lines){
  164. $tmp = array();
  165. foreach($lines as $line){
  166. /*** get the host name from a url ***/
  167. preg_match('#^(http://|https://)?([^/]+)#i', $line, $matches);
  168. array_push($tmp,trim($matches[0]));
  169. }
  170. sort($tmp);
  171. $tmp = array_unique($tmp);
  172. $tmp = array_values($tmp);
  173. return $tmp;
  174. }
  175. ?>