gwolff2005 Posted February 11, 2014 Share Posted February 11, 2014 Hi guys, I need your help, I am very desperate. I want people visitng my site with a mobile browser seeing a window saying, would you liek to switch to mobile view? - and the redirect. I found this code and I tried to implement it in my php fiel but nothing changes. Mobile borwser goes immediately to mobile view without window asking first, *What am I missing or doing wrong. you can test it out on guntmarwolffdotcom Thanks for your help! <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <?php if(isset($_GET['mVar'])){ session_start(); $_SESSION['views']=1; // Declaring a session to track the visits } if(!$_SESSION['views'] == 1){ // Checking the session and doing the redirection if ($_SERVER["QUERY_STRING"] == null){ echo " <script type=\"text/javascript\"> if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { window.location.replace('http://m.guntmarwolff.com');} </script> "; } } ?> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script> <!-- Add fancyBox main JS and CSS files --> <script type="text/javascript" src="http://www.guntmarwolff.com/fancyapps-fancyBox-v2.1.5-0-ge2248f4/source/jquery.fancybox.js"></script> <link rel="stylesheet" type="text/css" href="http://www.guntmarwolff.com/fancyapps-fancyBox-v2.1.5-0-ge2248f4/source/jquery.fancybox.css" media="screen" /> <script type="text/javascript" jQuery(document).ready(function () { jQuery.fancybox({ 'width': '75%', //Use percentage to maintain responsiveness 'height': '75%', 'autoScale': true, 'transitionIn': 'fade', 'transitionOut': 'fade', 'type': 'iframe', 'href': 'popupbox.htm' }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/286123-how-to-detect-a-mobile-browser/ Share on other sites More sharing options...
Mancent Posted February 11, 2014 Share Posted February 11, 2014 could do something like thisecho $_SERVER['HTTP_USER_AGEENT']; Quote Link to comment https://forums.phpfreaks.com/topic/286123-how-to-detect-a-mobile-browser/#findComment-1468544 Share on other sites More sharing options...
ginerjm Posted February 11, 2014 Share Posted February 11, 2014 Try starting your session first. Why do you want to make it a result of some condition? Just start it! Quote Link to comment https://forums.phpfreaks.com/topic/286123-how-to-detect-a-mobile-browser/#findComment-1468545 Share on other sites More sharing options...
Mancent Posted February 11, 2014 Share Posted February 11, 2014 if(preg_match("/chrome/",strtolower($_SERVER['HTTP_USER_AGENT']))) { //use a different css maybe } elseif(preg_match("/msie/",strtolower($_SERVER['HTTP_USER_AGENT']))) { //use a different css maybe } elseif(preg_match("/opera/",strtolower($_SERVER['HTTP_USER_AGENT']))) { //use a different css maybe } elseif(preg_match("/firefox/",strtolower($_SERVER['HTTP_USER_AGENT']))) { //use a different css maybe } elseif(preg_match("/safari/",strtolower($_SERVER['HTTP_USER_AGENT']))) { //use a different css maybe } then add some if statements Quote Link to comment https://forums.phpfreaks.com/topic/286123-how-to-detect-a-mobile-browser/#findComment-1468546 Share on other sites More sharing options...
gwolff2005 Posted February 11, 2014 Author Share Posted February 11, 2014 Thanks for your input@ ginerjmHow would I start the session first, if I want to detect First if it is mobile or not and if yes redirect. If that is not necessary how owuld I code it then?@Mancent:My problem is that the window does not pop up in my code which it is supposed to do. Quote Link to comment https://forums.phpfreaks.com/topic/286123-how-to-detect-a-mobile-browser/#findComment-1468547 Share on other sites More sharing options...
Mancent Posted February 12, 2014 Share Posted February 12, 2014 (edited) <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <?php if(isset($_GET['mVar'])){ session_start(); $_SESSION['views']=1; // Declaring a session to track the visits } else { session_start(); $_SESSION['views']=0; } if(!$_SESSION['views'] == 1){ // Checking the session and doing the redirection if ($_SERVER["QUERY_STRING"] == null){ echo " <script type=\"text/javascript\"> if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { window.location.replace('http://m.guntmarwolff.com');} </script> "; } } ?> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script> <!-- Add fancyBox main JS and CSS files --> <script type="text/javascript" src="http://www.guntmarwolff.com/fancyapps-fancyBox-v2.1.5-0-ge2248f4/source/jquery.fancybox.js"></script> <link rel="stylesheet" type="text/css" href="http://www.guntmarwolff.com/fancyapps-fancyBox-v2.1.5-0-ge2248f4/source/jquery.fancybox.css" media="screen" /> <script > jQuery(document).ready(function () { jQuery.fancybox({ 'width': '75%', //Use percentage to maintain responsiveness 'height': '75%', 'autoScale': true, 'transitionIn': 'fade', 'transitionOut': 'fade', 'type': 'iframe', 'href': 'popupbox.htm' }); }); </script> Edited February 12, 2014 by Mancent Quote Link to comment https://forums.phpfreaks.com/topic/286123-how-to-detect-a-mobile-browser/#findComment-1468554 Share on other sites More sharing options...
Mancent Posted February 12, 2014 Share Posted February 12, 2014 do you also have the popupbox.htm created?so your sending a var un the address bar.http://somewebsite.com/index.php?mVar=1 everything pop up just fine on PC I and my IPHONE Quote Link to comment https://forums.phpfreaks.com/topic/286123-how-to-detect-a-mobile-browser/#findComment-1468555 Share on other sites More sharing options...
sKunKbad Posted February 12, 2014 Share Posted February 12, 2014 You should consider Responsive Web Design. Browser detection just means more work for you because then you essentially maintain two websites. Quote Link to comment https://forums.phpfreaks.com/topic/286123-how-to-detect-a-mobile-browser/#findComment-1468559 Share on other sites More sharing options...
gwolff2005 Posted February 12, 2014 Author Share Posted February 12, 2014 @ Mancent. Thanks for the code. I will try it now. I have the popupbox.htm.@Skunkbad: Some of it I pull over from my normal site so I dont have to maintain too much... Quote Link to comment https://forums.phpfreaks.com/topic/286123-how-to-detect-a-mobile-browser/#findComment-1468568 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.