944,123 Members | Top Members by Rank

Ad:
  • PHP Code Snippet
  • Views: 1924
  • PHP RSS
0

CURL PHP Ready function !

by on Sep 12th, 2009
This is CURL Ready function , to use it just call do post if the page you are calling has post variables , or get if it has get variables
PHP Code Snippet (Toggle Plain Text)
  1. $random=rand(1, 100000);
  2. $cookie=$random . ".txt";
  3. $agent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
  4.  
  5. function doRequest($method, $url, $referer, $agent, $cookie, $vars) {
  6. $ch=curl_init();
  7. curl_setopt($ch, CURLOPT_URL, $url);
  8. if($referer != "") {
  9. curl_setopt($ch, CURLOPT_REFERER, $referer);
  10. }
  11. curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  12. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  14. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
  15. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
  16. if ($method == 'POST') {
  17. curl_setopt($ch, CURLOPT_POST, 1);
  18. curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
  19. }
  20. if (substr($url, 0, 5) == "https") {
  21. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  22. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
  23. }
  24. $data = curl_exec($ch);
  25. curl_close($ch);
  26. if ($data) {
  27. return $data;
  28. } else {
  29. return curl_error($ch);
  30. }
  31. }
  32.  
  33. function get($url, $referer, $agent, $cookie) {
  34. return doRequest('GET', $url, $referer, $agent, $cookie, 'NULL');
  35. }
  36.  
  37. function post($url, $referer, $agent, $cookie, $vars) {
  38. return doRequest('POST', $url, $referer, $agent, $cookie, $vars);
  39. }
Comments on this Code Snippet
Dec 16th, 2011
0

Re: CURL PHP Ready function !

what is the use of this code?
Light Poster
daniel36 is offline Offline
43 posts
since Nov 2011
Dec 16th, 2011
0

Re: CURL PHP Ready function !

@daniel you can use it to submit data to a script just as you're submitting a form, automatically. This script sends his request as a Firefox user, so it can bypass a filtering by User-Agent.

But it becomes useless if the receiving script expects also a captcha or a CSRF value.
The usage is simple:
PHP Syntax (Toggle Plain Text)
  1. $random=rand(1, 100000);
  2. $cookie=$random . ".txt";
  3. $agent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
  4.  
  5. # where to submit data
  6. $url = 'http://website.tld/data.php';
  7.  
  8. # the page from which is supposed to submit data
  9. # this is fake information, just as User-Agent
  10. $referer = 'http://website.tld/form.php';
  11.  
  12.  
  13. # form input fields and values to submit
  14. $vars = array(
  15. 'field_name_1' => 'value 1',
  16. 'field_name_2' => 'value 2'
  17. );
  18.  
  19. echo post($url, $referer, $agent, $cookie, $vars);
bye.
Posting Pro
cereal is offline Offline
524 posts
since Aug 2007
Message:
Previous Thread in PHP Forum Timeline: Dropdown - View results
Next Thread in PHP Forum Timeline: php alert / reminder script not working well





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC