Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. $ch = curl_init();
  2. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  3. curl_setopt($ch, CURLOPT_HEADER, 1);
  4. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  5. curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
  6. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  7. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); // remove Expect header to avoid 100 Continue situations
  8. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla [abbreviated]');
  9. curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__).'/cacert.pem');
  10. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.hq.txt'); // write cookies
  11. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.hq.txt'); // read cookies
  12. curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
  13. curl_setopt($ch, CURLOPT_URL, 'https://the_url.jsp');
  14.  
  15. $data = curl_exec($ch);
  16. $error= curl_error($ch);
  17. if(!empty($error))
  18. echo '<p>'.$error.'</p>';
  19. else
  20. echo '<p>ok</p>';
  21.  
  22. curl_setopt($ch, CURLOPT_POST, 1);
  23. curl_setopt($ch, CURLOPT_POSTFIELDS, $options);
  24. $data = curl_exec($ch);
  25. $error=curl_error($ch);
  26.  
  27. $options.=urlencode($fieldName).'='.urlencode($element->getAttribute('value'));
  28.  
  29. $options.=urlencode($fieldName).'='.urlencode($element->getAttribute('value'));
  30.  
  31. <?php
  32.  
  33. echo curl_grab_page("https://www.example.net/login.php", "https://www.example.net/", "username=foo&password=bar", "true", "null", "false");
  34.  
  35. // $url = page to POST data
  36. // $ref_url = tell the server which page you came from (spoofing)
  37. // $login = true will make a clean cookie-file.
  38. // $proxy = proxy data
  39. // $proxystatus = do you use a proxy ? true/false
  40.  
  41. function
  42. curl_grab_page($url,$ref_url,$data,$login,$proxy,$proxystatus){
  43. if($login == 'true') {
  44. $fp = fopen("cookie.txt", "w");
  45. fclose($fp);
  46. }
  47. $ch = curl_init();
  48. curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
  49. curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
  50. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
  51. curl_setopt($ch, CURLOPT_TIMEOUT, 40);
  52. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  53. if ($proxystatus == 'true') {
  54. curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
  55. curl_setopt($ch, CURLOPT_PROXY, $proxy);
  56. }
  57. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  58. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  59.  
  60. curl_setopt($ch, CURLOPT_URL, $url);
  61. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  62. curl_setopt($ch, CURLOPT_REFERER, $ref_url);
  63.  
  64. curl_setopt($ch, CURLOPT_HEADER, TRUE);
  65. curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  66. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  67. curl_setopt($ch, CURLOPT_POST, TRUE);
  68. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  69. ob_start();
  70. return curl_exec ($ch); // execute the curl command
  71. ob_end_clean();
  72. curl_close ($ch);
  73. unset($ch);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement