Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $timeout = 10;
- $username = 'me';
- $password = 'my password';
- $cookies_file = 'cookies.txt';
- /**************************************************
- Première requête : Connexion
- **************************************************/
- $url = 'https://what.cd/login.php';
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- if (preg_match('`^https://`i', $url))
- {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- }
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_NOBODY, true);
- // Forcer cURL à utiliser un nouveau cookie de session
- curl_setopt($ch, CURLOPT_COOKIESESSION, true);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, array(
- 'username' => $username,
- 'password' => $password,
- 'keeplogged' => '1',
- 'login' => 'Log in'
- ));
- // Fichier dans lequel cURL va écrire les cookies
- // (pour y stocker les cookies de session)
- curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies_file);
- curl_exec($ch);
- curl_close($ch);
- /**************************************************
- Seconde requête : Récupération du contenu
- **************************************************/
- $url = 'https://what.cd/ajax.php?action=index';
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- if (preg_match('`^https://`i', $url))
- {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- }
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_COOKIESESSION, true);
- // Fichier dans lequel cURL va lire les cookies
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies_file);
- $page_content = curl_exec($ch);
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- /****************************************
- Affichage
- ****************************************/
- if ($http_code == 200)
- {
- $json = json_decode($page_content, true);
- $quota = $json['response']['userstats']['ratio'];
- echo $quota;
- }
- else
- {
- echo 'Une erreur est survenue : '. $http_code;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement