Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Simple method which performs a login operation to Polish reddit-like "wykop.pl"
- * and fetches the number of notifications.
- *
- * @todo This is made just for fun! My activity on the websites was too low to
- * be granted access to Wykop API.
- *
- * @param string $operation token, login, notifs
- * @param string $username
- * @param string $passwod
- * @return int|string notifs count, token
- */
- function wykopnotifs($operation = 'token', $username = null, $password = null)
- {
- //start curl
- $ch = curl_init();
- $useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2';
- switch ($operation) {
- case 'notifs':
- $url = 'https://www.wykop.pl/powiadomienia/do-mnie/';
- break;
- case 'login':
- $token = wykopnotifs('token');
- curl_setopt( $ch, CURLOPT_POST, true );
- curl_setopt( $ch, CURLOPT_POSTFIELDS, 'user[username]=' . $username . '&user[password]=' . $password . '&__token=' . $token . '&submit=login' );
- case 'token':
- $url = 'https://www.wykop.pl/zaloguj/';
- break;
- }
- curl_setopt( $ch, CURLOPT_URL, $url );
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
- curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
- curl_setopt( $ch, CURLOPT_REFERER, 'https://www.wykop.pl/zaloguj/' );
- curl_setopt( $ch, CURLOPT_USERAGENT, $useragent );
- curl_setopt( $ch, CURLOPT_COOKIEJAR, 'cookie.txt' );
- curl_setopt( $ch, CURLOPT_COOKIEFILE, 'cookie.txt' );
- $result = curl_exec( $ch );
- curl_close( $ch );
- switch ($operation) {
- case 'notifs':
- if (stripos($result, "newregister")) {
- wykopnotifs('login', $username, $password);
- } else {
- return substr_count($result, "type-light-warning");
- }
- case 'token':
- $matches = [];
- preg_match("/name=\"__token\" value=\"(.+)?\"/i", $result, $matches);
- return $matches[1][0];
- }
- return $result;
- }
- //echo wykopnotifs('notifs', '**login**', '**password**');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement