Skip to content

Instantly share code, notes, and snippets.

@joebasurto
Last active June 5, 2020 12:20
Show Gist options
  • Save joebasurto/6b3b545a5c69d9b65c6142cd1d9f27c2 to your computer and use it in GitHub Desktop.
Save joebasurto/6b3b545a5c69d9b65c6142cd1d9f27c2 to your computer and use it in GitHub Desktop.
<?php
// Detect device
if(!function_exists('device_switch')){
function device_switch() {
$device = '';
if(stristr($_SERVER['HTTP_USER_AGENT'],'ipad')) {
$device = "ipad";
} else if(stristr($_SERVER['HTTP_USER_AGENT'],'iphone') || strstr($_SERVER['HTTP_USER_AGENT'],'iphone')) {
$device = "iphone";
} else if(stristr($_SERVER['HTTP_USER_AGENT'],'blackberry')) {
$device = "blackberry";
} else if(stristr($_SERVER['HTTP_USER_AGENT'],'android')) {
$device = "android";
}
if($device) {
return $device;
} return false; {
return false;
}
}
}
?>
<style>
/* Video */
.video {
position: relative;
padding-bottom: 56.25%;
height: 0;
overflow: hidden;
max-width: 100%;
}
.video iframe,
.video object,
.video embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
</style>
<?php
// Switch video for device
switch (device_switch()) {
case 'ipad':
echo "This is an ipad";
break;
case 'iphone':
echo "This is an iphone";
break;
case 'blackberry':
echo "This is a ipad";
break;
case 'android':
echo "This is an android";
break;
default :
echo '<div class="embed-container">
<iframe src="#" frameborder="0" allowfullscreen>
</iframe></div>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment