php curl with post field + cookies


SUBMITTED BY: sukamanahh

DATE: Jan. 1, 2016, 2:13 a.m.

FORMAT: Text only

SIZE: 707 Bytes

HITS: 748

  1. <?php
  2. //make grab function
  3. function grab($url=null, $par=null){
  4. $cookie_path = "cookies.txt";
  5. $ch = curl_init();
  6. curl_setopt($ch, CURLOPT_URL, $url);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  8. if(isset($par)){
  9. curl_setopt($ch, CURLOPT_POSTFIELDS, $par);
  10. }
  11. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path);
  12. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path);
  13. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  14. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  15. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  16. $html = curl_exec($ch);
  17. return $html;
  18. curl_close($ch);
  19. }
  20. //call function grab
  21. print grab("http://example.com", "param1Field=param1Value&param2Field=param2Value");
  22. ?>

comments powered by Disqus