Responsive website embedding

I haven’t written PHP in a while but this should be the idea:

<?php
	// Options
	
	$clientID = ''; // Required
	$channelName = 'ninja';
	
	$muted = true;
	$autoplay = true;
	
	$width = 640;
	$height = 360;
	
	// Options end
	
	$baseURL = 'https://api.twitch.tv/helix/';
	$url = $baseURL . 'streams?user_login=' . $channelName;
	
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Client-ID: ' . $clientID ]);
	$json = curl_exec($ch);
	curl_close($ch);

	$data = json_decode($json);
	if(count($data->data)) {
		$iframeSrc = 'https://player.twitch.tv/?channel=' . $channelName . '&muted=' . $muted . '&autoplay=' . $autoplay;
		echo '<iframe src="' . $iframeSrc . '" width="' . $width . '" height="' . $height . '" frameborder="0" scrolling="false" allowfullscreen="true"></iframe>';
	}
?>
1 Like