Akshay123 Posted April 8, 2010 Share Posted April 8, 2010 Hi I am a total newb with php, and I have some code that I need to use, but isnt working for me. Here it is: <?php include('/assets/UserAgentCheck/mobile_device_detect.php'); mobile_device_detect(true,true,true,true,true,true,false,false); if($mobile==true){ include('/m/index.html'); }else{ include('/d.html'); } exit; ?> all the file paths are correct the mobile_device_detect.php is supposed to detect a user agent, and return with a true or false indication right? the (mobile_device_detect(true,true,true,true,true,true,false,false) on line 3 is submitting imput to mobile_device_detect, which is required. however, it doesnt matter what user agent i use, it always goes to /d. Can someone help me? [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/198041-help-with-php/ Share on other sites More sharing options...
the182guy Posted April 8, 2010 Share Posted April 8, 2010 and return with a true or false indication right? Yes, but you are not catching the return value, look at your code: mobile_device_detect(true,true,true,true,true,true,false,false); if($mobile==true){ // $mobiles was not set anywhere Use $mobile = mobile_device_detect(true,true,true,true,true,true,false,false); Link to comment https://forums.phpfreaks.com/topic/198041-help-with-php/#findComment-1039161 Share on other sites More sharing options...
Akshay123 Posted April 8, 2010 Author Share Posted April 8, 2010 thanks, that helped a lot Link to comment https://forums.phpfreaks.com/topic/198041-help-with-php/#findComment-1039172 Share on other sites More sharing options...
Akshay123 Posted April 8, 2010 Author Share Posted April 8, 2010 Another Question: So suppose a person was using a mobile version, and wanted to switch to the desktop version. Do you think I could use this link? (http://localhost/?mobile==false) or anything like that in the URL? Link to comment https://forums.phpfreaks.com/topic/198041-help-with-php/#findComment-1039181 Share on other sites More sharing options...
nethnet Posted April 8, 2010 Share Posted April 8, 2010 That would only work if register globals was enabled. So, essentially, no. You could provide a link somewhere on your page that allows people to switch between the versions, and pass a flag in your URL. Something like.. ?switch=desktop $switch = $_GET['switch']; $mobile = ($switch == "desktop" && $mobile == TRUE) ? FALSE : TRUE; Link to comment https://forums.phpfreaks.com/topic/198041-help-with-php/#findComment-1039186 Share on other sites More sharing options...
Akshay123 Posted April 8, 2010 Author Share Posted April 8, 2010 Wait, I'm confused with the code you gave me, it would look like this for /index.php, right? <?php include('assets/UserAgentCheck/mobile_device_detect.php'); $mobile = mobile_device_detect(true,true,true,true,true,true,false,false); if($mobile==true){ include('/m/index.html'); }else{ include('d.html'); } exit; $switch = $_GET['switch']; $mobile = ($switch == "desktop" && $mobile == TRUE) ? FALSE : TRUE; ?> so then if i understood that part, I would create a link in /m/index.html (my mobile page) pointing to http://localhost/?switch=desktop. However when I do that, the server just ignored my query string. Just regular http://localhost/m/index.html showed up. Link to comment https://forums.phpfreaks.com/topic/198041-help-with-php/#findComment-1039201 Share on other sites More sharing options...
nethnet Posted April 9, 2010 Share Posted April 9, 2010 Put those two lines of code before your if statement. Link to comment https://forums.phpfreaks.com/topic/198041-help-with-php/#findComment-1039782 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.