Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function page_fetch($url)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_VERBOSE, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_AUTOREFERER, false);
- curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_ENCODING, '');
- curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
- if (!$html = curl_exec($ch))
- {
- $html = file_get_contents($url);
- }
- curl_close($ch);
- return $html;
- }
- $chan_info = page_fetch("https://api.twitch.tv/kraken/streams?channel=".$stream_info['name']);
- $chan_fetch = json_decode($chan_info, true);
- if(isset($chan_fetch['_total']) AND $chan_fetch['_total'] > 0)
- {
- if(!isset($chan_fetch['streams'][0]['viewers'])) { $chan_fetch['streams'][0]['viewers'] = 0; }
- mysql_query("UPDATE `users` SET viewers = ".floor($chan_fetch['streams'][0]['viewers'])." WHERE name = ".$stream_info['name']) or die(mysql_error());
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement