将用户重定向到移动网站,或者如果用户点击完整网站设置Cookie并将用户保留在完整网站上?

I have a header.php file which is included into all my desktop sites, including index.php, about.php etc.

I am redirecting my mobile users to my mobile site http://m.hewdenportal.co.uk using the following code in header.php:

header.php (Desktop Site Header file):

<?php

if (!isset($_COOKIE['nomobile'])) { ?>
<script>
function urlParam(name){
            var results = new RegExp('[\\?&amp;]' + name + '=([^&amp;#]*)').exec(window.location.href);
            if(results)
                return results[1] || 0;
            else
                return '';
        }

        if(urlParam('view') == 'full'){ 
        }
        if(urlParam('view') == ''){
            // <![CDATA[
            var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
            if (mobile) { 
                    document.location = "http://m.hewdenportal.co.uk";  
            }  
            // ]]>
        }
</script>
<?php } ?>

The idea here is if there is no cookie set then my jQuery should be read by the browser and the user should get redirected to my mobile site if they're using a mobile device.

Next, on the mobile site, I give the user the option to navigate to the full site like so:

Mobile site:

<a href="full_site.php" data-ajax="false">Full Site</a>

full_site.php:

<?php 
setcookie("nomobile", time()+3600);  /* expire in 1 hour */
header('Location: http://www.hewdenportal.co.uk');
?>

in my full_site.php file i then try to start a cookie which will last until the user closes their session on my site. Then the user gets redirected to the full site.

The cookie is then checked if exists in my header.php file so the user is not redirected back to the mobile site for the entire duration they have the site open. Until they leave the site and come back to the site later on then they are taken back to the mobile site.

The problem I am having is the php code doesn't seem to be checking for the cookie and it's constantly redirecting the user to the mobile site. Please can someone show me the best way to do this?