Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Set the broadcaster name to lowercase.
- $BroadcasterLower = strtolower($_GET["Broadcaster"]);
- // Set variable of GET data.
- $GeneralQuery = $_GET["GeneralQuery"];
- // Defaullt fallback in case nothing was entered for how many followers to print.
- if (empty($_GET["GeneralQuery"]) || $_GET["GeneralQuery"] == null)
- {
- $GeneralQuery = 5;
- }
- // Check to make sure input is numeric.
- if(is_numeric($GeneralQuery))
- {
- // More than 1, less than 25 (don't want to run into too long of a string).
- if($GeneralQuery > "25" || $GeneralQuery < "0")
- {
- echo $GeneralQuery . ', is outside of accepted range, 1-25 is the accepted range.';
- }
- // Good to good, valid numeric input between 1-25.
- else
- {
- // Inject lowercase names to get the last followers.
- $ch = curl_init("https://api.twitch.tv/kraken/channels/" . $BroadcasterLower . "/follows?direction=DESC&limit=" . $GeneralQuery . "&offset=0");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $result = curl_exec($ch);
- curl_close($ch);
- // Decode the above JSON data.
- $LastFollowersCheckData = json_decode($result, true);
- // Only print the last follower, get the wording right... blah blah blah.
- echo htmlspecialchars($_GET["Broadcaster"]) . "'s last ";
- // Wording for only the last follower.
- if($GeneralQuery == 1)
- {
- echo 'follower is: ';
- }
- else
- {
- // Wording for the last 2-25 followers.
- echo $GeneralQuery . ' followers are: ';
- }
- for ($x=0; $x <= $GeneralQuery; $x++)
- {
- echo $LastFollowersCheckData["follows"][$x]["user"]["display_name"];
- // Die after the last follower, without having a "," at the end of it.
- if($x == ($GeneralQuery - 1))
- {
- die();
- }
- echo ', ';
- }
- }
- }
- // Bad input.
- else
- {
- echo 'You need to input a valid numeric between 1-25';
- }
- ?>
- Example: LastFollowers.php?Broadcaster=TwitchBroadcaster&GeneralQuery=25
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement