Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

Check Spotify Invites - PHP Code Bank


Check Spotify Invites
A little script i coded last night to help me find a unused Spotify invite from a list with 1700 invites.
                <?php
// Set max_execution_time to 1 day, since this script is gonna take a while
ini_set(max_execution_time,24*60*60);

class SpotifyCheck
{
	
	private $invites;

	public function __construct( $file )
	{
// Open file specified and explode the whole file by every newline into an array
		$handle = fopen( $file, "r" );
		$contents = fread( $handle, filesize( $handle ) );
		$this->invites = explode( "\n", $content );
		fclose( $handle );
		
		foreach( $this->invites as $v )
		{
// Execute custom function FetchInvitePage for each invite, with invite as argument.
			$r = $this->FetchInvitePage( $v );
// Check if Invitation is used or invalid, if not then redirect to the invite page.
			if( !eregi( 'This invitation token has already been used', $r ) && !eregi('This is not a valid invitation token', $r ) )
			{
				die(header("Location: ".$url.""));
			}
		}	
	}
	
	private function FetchInvitePage( $code )
	{
// A little eregi to sort if the line is only the invite code or an entire URL.	
		$url = ( eregi( "^(https?://www.spotify.com/en/invitation/[a-zA-Z0-9]{16})$", $code ) ? $code : "https://www.spotify.com/en/invitation/".$code );
// And then use cURL to fetch the page
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
// These SSL OPTS were hell to find out :|
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		$chresult = curl_exec($ch);
		curl_close($ch);
// Return page contents.
		return $chresult;
	}
	
	
}
// Done ^_^
?>
            
Comments
ghost's avatar
ghost 13 years ago

Did it work? How long did it take?

ghost's avatar
ghost 13 years ago

It did work as expected!

And the whole execution time was about 7 hours on a 0,25Mbit DSL line.