Advertisement
Guest User

Thahelper - cURL & PHP - Website Login

a guest
Jan 31st, 2015
25,924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.94 KB | None | 0 0
  1. <?php
  2.  
  3. //Upload a blank cookie.txt to the same directory as this file with a CHMOD/Permission to 777
  4. function login($url,$data){
  5.     $fp = fopen("cookie.txt", "w");
  6.     fclose($fp);
  7.     $login = curl_init();
  8.     curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
  9.     curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
  10.     curl_setopt($login, CURLOPT_TIMEOUT, 40000);
  11.     curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
  12.     curl_setopt($login, CURLOPT_URL, $url);
  13.     curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  14.     curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
  15.     curl_setopt($login, CURLOPT_POST, TRUE);
  16.     curl_setopt($login, CURLOPT_POSTFIELDS, $data);
  17.     ob_start();
  18.     return curl_exec ($login);
  19.     ob_end_clean();
  20.     curl_close ($login);
  21.     unset($login);    
  22. }                  
  23.  
  24. function grab_page($site){
  25.     $ch = curl_init();
  26.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  27.     curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  28.     curl_setopt($ch, CURLOPT_TIMEOUT, 40);
  29.     curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
  30.     curl_setopt($ch, CURLOPT_URL, $site);
  31.     ob_start();
  32.     return curl_exec ($ch);
  33.     ob_end_clean();
  34.     curl_close ($ch);
  35. }
  36.  
  37. function post_data($site,$data){
  38.     $datapost = curl_init();
  39.         $headers = array("Expect:");
  40.     curl_setopt($datapost, CURLOPT_URL, $site);
  41.         curl_setopt($datapost, CURLOPT_TIMEOUT, 40000);
  42.     curl_setopt($datapost, CURLOPT_HEADER, TRUE);
  43.         curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers);
  44.     curl_setopt($datapost, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  45.     curl_setopt($datapost, CURLOPT_POST, TRUE);
  46.     curl_setopt($datapost, CURLOPT_POSTFIELDS, $data);
  47.         curl_setopt($datapost, CURLOPT_COOKIEFILE, "cookie.txt");
  48.     ob_start();
  49.     return curl_exec ($datapost);
  50.     ob_end_clean();
  51.     curl_close ($datapost);
  52.     unset($datapost);    
  53. }
  54.  
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement