Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @author _Tobias
- * @package difm-player
- * @license DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE / http://www.wtfpl.net/txt/copying/
- */
- /**
- * Variables
- */
- // Expiration time of the new cookie in days.
- $expiration = 30;
- // Name of the cookie we need to read from.
- $cookieName = 'DI.fm player';
- /**
- * Main execution
- */
- // Disable some unnecessary headers.
- header('Content-Type: ');
- header_remove('X-Powered-By');
- // Check whether the replacement listen key is given in POST.
- if(@empty($_POST['key'])) {
- // If this is not the case, show an error message.
- header('HTTP/1.1 400 Bad Request');
- die('Missing parameter "key"');
- }
- // The new cookie array will go in here.
- $cookie = null;
- // PHP puts the cookies in its $_COOKIE array by a key with some characters replaced, this is the right element.
- $clientCookie = @$_COOKIE[preg_replace('/[^a-zA-Z0-9]/', '_', $cookieName)];
- // Check whether the cookie is valid. Otherwise, use a new empty array.
- if($clientCookie) {
- $cookie = @json_decode($clientCookie, true);
- if(!$cookie)
- $cookie = array();
- }
- else
- $cookie = array();
- // Fill the 'premium' element of the array with the key given in POST.
- $cookie['premium'] = $_POST['key'];
- // Send the new cookie to the client in the headers.
- setcookie(rawurlencode($cookieName), json_encode($cookie), time() + 86400 * $expiration, '/');
- // Redirect the user to the player.
- header('Location: /play/');
- // Make sure there isn't any content sent conflicting with the redirect.
- exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement