Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. <?php
  2.  
  3. function page_fetch($url)
  4.     {
  5.         $ch = curl_init();
  6.         curl_setopt($ch, CURLOPT_URL, $url);
  7.         curl_setopt($ch, CURLOPT_VERBOSE, 1);
  8.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  9.         curl_setopt($ch, CURLOPT_AUTOREFERER, false);
  10.         curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  11.         curl_setopt($ch, CURLOPT_HEADER, 0);
  12.         curl_setopt($ch, CURLOPT_ENCODING, '');
  13.         curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
  14.         if (!$html = curl_exec($ch))
  15.             {
  16.                 $html = file_get_contents($url);
  17.             }
  18.         curl_close($ch);
  19.         return $html;
  20.     }
  21.  
  22. $chan_info = page_fetch("https://api.twitch.tv/kraken/streams?channel=".$stream_info['name']);
  23. $chan_fetch = json_decode($chan_info, true);
  24.  
  25. if(isset($chan_fetch['_total']) AND $chan_fetch['_total'] > 0)
  26.     {
  27.         if(!isset($chan_fetch['streams'][0]['viewers'])) { $chan_fetch['streams'][0]['viewers'] = 0; }
  28.         mysql_query("UPDATE `users` SET viewers = ".floor($chan_fetch['streams'][0]['viewers'])." WHERE name = ".$stream_info['name']) or die(mysql_error());
  29.     }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement