Advertisement
_Tobias

one 2 rule dem all

Oct 6th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @author _Tobias
  4.  * @package difm-player
  5.  * @license DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE / http://www.wtfpl.net/txt/copying/
  6.  */
  7.  
  8.  
  9. /**
  10.  * Variables
  11.  */
  12.  
  13. // Expiration time of the new cookie in days.
  14. $expiration = 30;
  15.  
  16. // Name of the cookie we need to read from.
  17. $cookieName = 'DI.fm player';
  18.  
  19.  
  20. /**
  21.  * Main execution
  22.  */
  23.  
  24. // Disable some unnecessary headers.
  25. header('Content-Type: ');
  26. header_remove('X-Powered-By');
  27.  
  28. // Check whether the replacement listen key is given in POST.
  29. if(@empty($_POST['key'])) {
  30.     // If this is not the case, show an error message.
  31.     header('HTTP/1.1 400 Bad Request');
  32.     die('Missing parameter "key"');
  33. }
  34.  
  35. // The new cookie array will go in here.
  36. $cookie = null;
  37.  
  38. // PHP puts the cookies in its $_COOKIE array by a key with some characters replaced, this is the right element.
  39. $clientCookie = @$_COOKIE[preg_replace('/[^a-zA-Z0-9]/', '_', $cookieName)];
  40.  
  41. // Check whether the cookie is valid. Otherwise, use a new empty array.
  42. if($clientCookie) {
  43.     $cookie = @json_decode($clientCookie, true);
  44.     if(!$cookie)
  45.         $cookie = array();
  46. }
  47. else
  48.     $cookie = array();
  49.  
  50. // Fill the 'premium' element of the array with the key given in POST.
  51. $cookie['premium'] = $_POST['key'];
  52.  
  53. // Send the new cookie to the client in the headers.
  54. setcookie(rawurlencode($cookieName), json_encode($cookie), time() + 86400 * $expiration, '/');
  55.  
  56. // Redirect the user to the player.
  57. header('Location: /play/');
  58.  
  59. // Make sure there isn't any content sent conflicting with the redirect.
  60. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement