Advertisement
Guest User

CURL test code

a guest
Mar 12th, 2016
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1.  
  2. /////////////////////////////////////////////////////////////////////////// Login Source code
  3. $username = trim($values["email"]);
  4. $password = trim($values["password"]);
  5.  
  6. //set the directory for the cookie using defined document root var
  7. $dir = DOC_ROOT."/ctemp";
  8. //build a unique path with every request to store
  9. //the info per user with custom func.
  10. $path = build_unique_path($dir);
  11.  
  12. //login form action url
  13. $url="http://codequiz.saudqq.com/quiz1/login.php";
  14. $postinfo = "email=".$username."&password=".$password;
  15.  
  16. $cookie_file_path = $path."/cookie.txt";
  17.  
  18. $ch = curl_init();
  19. curl_setopt($ch, CURLOPT_HEADER, false);
  20. curl_setopt($ch, CURLOPT_NOBODY, false);
  21. curl_setopt($ch, CURLOPT_URL, $url);
  22. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  23.  
  24. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
  25. //set the cookie the site has for certain features, this is optional
  26. curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
  27. curl_setopt($ch, CURLOPT_USERAGENT,
  28. "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
  29. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  30. curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
  31. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  32. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  33.  
  34. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); // "GET"
  35. curl_setopt($ch, CURLOPT_POST, 1);
  36. curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
  37. curl_exec($ch);
  38.  
  39. //page with the content I want to grab
  40. curl_setopt($ch, CURLOPT_URL, "http://codequiz.saudqq.com/quiz1/");
  41. //do stuff with the info with DomDocument() etc
  42. $html = curl_exec($ch);
  43. curl_close($ch);
  44.  
  45.  
  46. ////////////////////////////////////////////////////////////////////////////// upload file
  47. <?php
  48. if ($_POST['submit']) {
  49. $uploadDir = "/uploads/";
  50. $RealTitleID = $_FILES['Filedata']['name'];
  51. $ch = curl_init("http://codequiz.saudqq.com/quiz1/upload.php");
  52. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  53. curl_setopt($ch, CURLOPT_POST, 1);
  54. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  55. $args['file'] = new CurlFile($_FILES['Filedata']['tmp_name'],'file/exgpd',$RealTitleID);
  56. curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
  57. $result = curl_exec($ch);
  58. }
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement