Advertisement
Guest User

Untitled

a guest
Jun 15th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. <?php
  2.  
  3. $timeout = 10;
  4.  
  5. $username = 'me';
  6. $password = 'my password';
  7.  
  8. $cookies_file = 'cookies.txt';
  9.  
  10. /**************************************************
  11. Première requête : Connexion
  12. **************************************************/
  13.  
  14. $url = 'https://what.cd/login.php';
  15.  
  16. $ch = curl_init($url);
  17.  
  18. curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
  19. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  20. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  21.  
  22. if (preg_match('`^https://`i', $url))
  23. {
  24. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  25. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  26. }
  27.  
  28. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  29. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  30. curl_setopt($ch, CURLOPT_NOBODY, true);
  31.  
  32. // Forcer cURL à utiliser un nouveau cookie de session
  33. curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  34.  
  35. curl_setopt($ch, CURLOPT_POST, true);
  36. curl_setopt($ch, CURLOPT_POSTFIELDS, array(
  37. 'username' => $username,
  38. 'password' => $password,
  39. 'keeplogged' => '1',
  40. 'login' => 'Log in'
  41. ));
  42.  
  43. // Fichier dans lequel cURL va écrire les cookies
  44. // (pour y stocker les cookies de session)
  45. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies_file);
  46.  
  47. curl_exec($ch);
  48.  
  49. curl_close($ch);
  50.  
  51. /**************************************************
  52. Seconde requête : Récupération du contenu
  53. **************************************************/
  54.  
  55. $url = 'https://what.cd/ajax.php?action=index';
  56.  
  57. $ch = curl_init($url);
  58.  
  59. curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
  60. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  61. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  62.  
  63. if (preg_match('`^https://`i', $url))
  64. {
  65. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  66. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  67. }
  68.  
  69. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  70. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  71. curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  72.  
  73. // Fichier dans lequel cURL va lire les cookies
  74. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies_file);
  75.  
  76. $page_content = curl_exec($ch);
  77.  
  78. $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  79.  
  80. curl_close($ch);
  81.  
  82. /****************************************
  83. Affichage
  84. ****************************************/
  85.  
  86. if ($http_code == 200)
  87. {
  88. $json = json_decode($page_content, true);
  89.  
  90. $quota = $json['response']['userstats']['ratio'];
  91. echo $quota;
  92. }
  93. else
  94. {
  95. echo 'Une erreur est survenue : '. $http_code;
  96.  
  97. }
  98. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement