You should use redirects
and headers
This is just example if you are using PHP web server:
index.html (from here):
<script>
function detectmob() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
){
window.location="action.php?mob=true";
}
else {
window.location="action.php?mob=false";
}
}
detectmob();
<script>
action.php:
<?php
if(!$_GET["mob"]){
define("var","myvar");
require("yourfile.php");
}else{
echo "Mobile device detected!";
}?>
yourfile.php:
<?php
if(!defined("var")){echo "no entry";return;// var not defined hence mobile device
}?>
<!-- not return hence not mobile device -->
<!-- begin other codes --->
Note: I am not guaranteed that page will load on only desktop device. Because PHP or back end languages doesn't really know that device is Desktop or Mobile.
Because of redirect are from simple HTML page, it can be changed by any person that editing DOM element or Direct specification of URL. Hence your idea of loading website on only desktop device will not perfect from all