PHP - Php Mobile Device Detection & Redirection Script
Hi Everyone:
Can anyone show me or direct me to a PHP PHP Mobile Device Detection & Redirection Script. I use to use this when doing ASP: Code: [Select] <% Dim user_agent, mobile_browser, Regex, match, mobile_agents, mobile_ua, i, size user_agent = Request.ServerVariables("HTTP_USER_AGENT") mobile_browser = 0 Set Regex = New RegExp With Regex .Pattern = "(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|windows ce|pda|mobile|mini|palm)" .IgnoreCase = True .Global = True End With match = Regex.Test(user_agent) If match Then mobile_browser = mobile_browser+1 If InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/vnd.wap.xhtml+xml") Or Not IsEmpty(Request.ServerVariables("HTTP_X_PROFILE")) Or Not IsEmpty(Request.ServerVariables("HTTP_PROFILE")) Then mobile_browser = mobile_browser+1 end If mobile_agents = Array("w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq", "bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "winw", "xda", "xda-") size = Ubound(mobile_agents) mobile_ua = LCase(Left(user_agent, 4)) For i=0 To size If mobile_agents(i) = mobile_ua Then mobile_browser = mobile_browser+1 Exit For End If Next If mobile_browser>0 Then Response.Redirect("http://www.sp.com/SPMOBI/MOBI.asp") End If %> Is there a PHP equivalent of this? As always, I appreciate to wisdom of the board. Thanks! Similar TutorialsHi, how can i detect if my website is being open in mobile type all devices instead of computer Please help This topic has been moved to Other. http://www.phpfreaks.com/forums/index.php?topic=347646.0 Hey everyone! I'm an absolute beginner with PHP but in my struggle with a project, I keep seeing 'PHP' so here I am, asking for help from the experts. I have a client who wants a basic 'mobile version' of their website to be displayed automatically when people view it on a mobile device (iPhone, Android especially). I've tried a couple of JavaScript solutions but, for some reason, they wouldn't work on Android (despite the author of the code specifying that it 'should do'). This has led me to look into a server-side solution. If the user visits the site, e.g. www.mysite.com on a mobile device, I want it to redirect to the subdomain m.mysite.com (I could even use www.mysite.com/mobile). On this 'mobile version' there should be a link to view the full site (and vice versa). Does anyone know of any tried and tested methods to achieve this? I'm literally pulling my hair out now with this. Thank you so much in advance. Have a great day. Regards Darryl Hi guys, I am creating a script as I am using this to detection the proxy server levels. <?php //proxy levels //Level 3 Elite Proxy, connection looks like a regular client //Level 2 Anonymous Proxy, no ip is forworded but target site could still tell it's a proxy //Level 1 Transparent Proxy, ip is forworded and target site would be able to tell it's a proxy if(!$_SERVER['HTTP_X_FORWARDED_FOR'] && !$_SERVER['HTTP_VIA'] && !$_SERVER['HTTP_PROXY_CONNECTION']){ echo '3'; } elseif(!$_SERVER['HTTP_X_FORWARDED_FOR']){ echo '2'; } else echo '1'; ?> I want the script to check the ip that if the proxy server is a Codeen/PlanetLab and BotNet proxy servers, then place on level one and if they are safe/unsafe to use. I cannot find the code to do the methods. Please help me! Thanks in advance. Hi guys, Before I am going to create php script to make a proxy detection, I want to ask that if it possible to create a method that checking whether if the proxy server is a located governments or fbi. Is it possible? If so, what method I would use? Thanks, Mark I have a php script that detects the user's mobile phone and browser and some other stuff. To display this info, I use: <?php echo htmlentities($_SERVER['HTTP_USER_AGENT']); ?> But this outputs a lot more than I need. It outputs the handset, the browser, the version etc... like this: Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53 Does anyone know what I need to change in the script just so I can have it display the handset name? All I want it to do is say something like "You have a Samsung Galaxy Note II" I have attached the mobile_detect script but I dont know what to edit because I don't really know php. Appreciate the help, JH Attached Files Mobile_Detect.php.zip 22.37KB 1 downloads I'm trying to detect a user's mobile handset when he visits my web page. So on my web page, I have placed this Javascript code: Is it possible to retrieve a visitor's iPhone device id? If so, how? If it's not possible, do all iPhones accept cookies? Hi, I have tried a lot of different scripts for detect and redirect for device for mobile and they seem to work ok on mac but ie does not load the page are there any scripts that work? I have a main site that sits at the usual www.domain.co.uk address and then i have a mobile site at www.domain.co.uk/phone i want to be able to have nay mobile users when accessing www.domain.co.uk be automaticly redirected to www.domain.co.uk/phone with that working in ie? any help please? thanks, I'm Trying to INSERT Data into mysql which is generated from biomatric attendance device. what i wanted to do is to save these data into mysql database. <?php include 'db.php'; ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> <!-- <script type="text/javascript" src="load.js"></script> --> <link rel="stylesheet" href="style.css"> <title>Live Attendance</title> </head> <?php include("zklib/zklib.php"); $zk = new ZKLib("192.168.1.3", 4370); $ret = $zk->connect(); sleep(1); if ( $ret ): $zk->disableDevice(); sleep(1); ?> <body> <table border="1" cellpadding="5" cellspacing="2" style="float: left; margin-right: 10px;"> <tr> <th colspan="5">Data User</th> </tr> <tr> <th>UID</th> <th>ID</th> <th>Name</th> <th>Role</th> <th>Password</th> </tr> <?php try { //$zk->setUser(1, '1', 'Admin', '', LEVEL_ADMIN); $user = $zk->getUser(); sleep(1); while(list($uid, $userdata) = each($user)): if ($userdata[2] == LEVEL_ADMIN) $role = 'ADMIN'; elseif ($userdata[2] == LEVEL_USER) $role = 'USER'; else $role = 'Unknown'; ?> <tr> <td><?php echo $uid ?></td> <td><?php echo $userdata[0] ?></td> <td><?php echo $userdata[1] ?></td> <td><?php echo $role ?></td> <td><?php echo $userdata[3] ?> </td> </tr> <?php endwhile; } catch (Exception $e) { header("HTTP/1.0 404 Not Found"); header('HTTP', true, 500); // 500 internal server error } //$zk->clearAdmin(); if (isset($_POST['create_post'])) { $query = "INSERT INTO attendance(idx)"; $query .= "VALUES ($id)"; $submittodbquery = mysqli_query($con,$query); if (!$submittodbquery) { die("Failed up upload " . mysqli_error($con)); }else { echo "updated"; } } ?> </table> <button id="submit" type="submit" name="create_post" class="btn btn-danger">Submit New Post</button> <?php $name = $userdata[1]; $attendance = $zk->getAttendance(); sleep(1); while(list($idx, $attendancedata ) = each($attendance)): if ( $attendancedata[2] == 1 ) $status = 'Check Out'; else $status = 'Check In'; ?> <?php $idx ?> <?php $attendancedata[0] ?> <?php $attendancedata[1] ?> <?php $status ?> <?php date( "d-m-Y", strtotime( $attendancedata[3] ) ) ?> <?php date( "H:i:s", strtotime( $attendancedata[3] ) ) ?> <?php // custom code if (isset($_POST['submit'])) { $query = "INSERT INTO attendance(idx)"; $query .= "VALUES ($idx)"; $submittodbquery = mysqli_query($con,$query); if (!$submittodbquery) { die("Failed up upload " . mysqli_error($con)); }else { echo "updated"; } } ?> <?php endwhile ?> </table> <input type="submit" name="submit" value="Update Database"> <?php $zk->enableDevice(); sleep(1); $zk->disconnect(); endif ?> </body> </html> Thanks for reading my question ..
This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=318425.0 i try this code. Code: [Select] <video width="320" height="240" controls="controls" autobuffer="autobuffer"> <source src="data:video/mp4;base64,AAAA<?php echo chunk_split(base64_encode(trim(file_get_contents('kecak.mp4')))); ?>" type="video/mp4" /> Your browser does not support the video tag. </video> it's work when i play in Notebook(safari, firefox) but not work when i play on IPAD2(safari) or Samsung Galaxy(Opera). i think the problem is in Code: [Select] src="data:video/mp4;base64,AAAA<?php echo chunk_split(base64_encode(trim(file_get_contents('kecak.mp4')))); ?>because when i replace with Code: [Select] src="kecak.mp4"it's work at all device and browser. i must use base64_encode(trim(file_get_contents('kecak.mp4'))) because in real my case it's come from response from RESTFul to delivery video via http. string response from http same with base64_encode(trim(file_get_contents('kecak.mp4'))). thanks u for help :-) Hello guys, I am new to PHP programming. I am trying to figure out how to use PHP language to transmit/write characters to a USB port device at 9600 baud rate 8-N-1. Basically I just need the PHP coding to allow me to send stuff to the USB device but I have no idea how I can interface this. I did some researching but most were for RS-232 COM Port. I can't find the proper one for USB. If someone can help me out, that would be awesome. Thank you! I have done some searching and digging, but it seems everyone has their own ways of doing things, some more effective than others. I have a web design portfolio website, which uses a "coinslider" flash slideshow. It looks awesome in FF, but IE6/etc users cant view it properly. How can I create a PHP if/then to detect if they are using a sub-par browser, and display a more simple slideshow? That way it will work for all users, and those with Firefox and similar browsers can view the more interesting slideshow. Thanks. Hi I want to do facial detection (http://corpocrat.com/2009/08/18/automatic-face-detection-with-php-in-linux/), any ways to do it without installing extra stuff (directly, going to try the php.ini add from a php.index) into PHP, as my web host does not allow that. I use this script to detect a browser IP, however it doesn't work with IPv6. http://phptutorial.info/iptocountry/the_script.html Any ideas what is required to make it work with both IPv4 & IPv6?
Thanks Hi, I would like to be able to receive and emain on what pages users are getting 404 errors (or any other for that fact). I have the directive in my .htaccess to redirect missing pages to my custom 404.php page. However, despite trying a number of tutorial on how to get it to email me the url they tried to access, I can not get it to work. My code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Please Wait</title> <meta http-equiv="refresh" content="0; url=http://www.mysite.co.uk" /> </head> <body> <?PHP $ip = getenv ("REMOTE_ADDR"); $requri = getenv ("REQUEST_URI"); $servname = getenv ("SERVER_NAME"); $combine = $ip . " tried to load " ; $url = $servname . $requri ; $httpref = getenv ("HTTP_REFERER"); $httpagent = getenv ("HTTP_USER_AGENT"); $today = date("D M j Y g:i:s a T"); $message2 = "On $today, $combine:\n http://www.$url\n User Agent = $httpagent \n $httpref "; $to = "my.email@domain.com"; $subject = "404 Error Report"; $from = "From:no-reply@domain.com\r\n"; mail($to, $subject, $message2, $from); ?> </body> </html> I just get: On Mon Jan 16 2012 9:55:57 am UTC, 82.153.239.221 tried to load : http://www.www.mysite.co.uk/404.php User Agent = Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; .NET CLR 2.0.50727; .NET CLR 3.5.30729) Anyone know of a fairly reliable image nudity detection script? That is open source (PHP or JS)? I was on a proxy and it didnt detect it, idk why. if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']) || !empty($_SERVER['HTTP_X_FORWARDED']) || !empty($_SERVER['HTTP_FORWARDED_FOR']) || empty($_SERVER['HTTP_CONNECTION']) || $hostaddr == "." || stripos($hostaddr, "tor-exit") || !empty($_SERVER['HTTP_VIA']) || empty($_SERVER['HTTP_ACCEPT_ENCODING']) || in_array($_SERVER['REMOTE_PORT'], array(8080,80,6588,8000,3128,553,554)) ) { die('on Proxy'); Here is my simple script for user browser and OS detection: $agent = $_SERVER['HTTP_USER_AGENT']; if (strstr($agent,"Windows")) {$os = "Windows";} if (strstr($agent,"Windows NT 6")) {$os = "Windows 7";} if (strstr($agent,"Linux")) {$os = "Linux";} if (strstr($agent,"Intel Mac OS X")) {$os = "OS X";} if (strstr($agent,"OpenBSD")) {$os = "BSD";} if (strstr($agent,"FreeBSD")) {$os = "FreeBSD";} if (strstr($agent,"Firefox/3")) {$br = "Firefox 3";} if (strstr($agent,"Firefox/2")) {$br = "Firefox 2";} if (strstr($agent,"Firefox/1")) {$br = "Firefox 1";} if (strstr($agent,"Phoenix/")) {$br = "Phoenix (Mozilla lite)";} if (strstr($agent,"MSIE 6")) {$br = "IE 6";} if (strstr($agent,"MSIE 7")) {$br = "IE 7";} if (strstr($agent,"MSIE 8")) {$br = "IE 8";} if (strstr($agent,"Netscape6/6")) {$br = "Netscape 6";} if (strstr($agent,"Opera")) {$br = "Opera";} if (strstr($agent,"Opera") and strstr($agent,"Version/10")) {$br = "Opera 10";} if (strstr($agent,"Opera") and strstr($agent,"Version/9")) {$br = "Opera 9";} if (strstr($agent,"Chrome") and strstr($agent,"Chrome/5")) {$br = "Chrome 5";} if (strstr($agent,"Safari/")) {$br = "Safari";} if (strstr($agent,"Safari/") and strstr($agent,"Version/5")) {$br = "Safari 5";} if (strstr($agent,"Safari/") and strstr($agent,"Version/4")) {$br = "Safari 4";} if (strstr($agent,"Safari/") and strstr($agent,"Version/3")) {$br = "Safari 3";} if (strstr($agent,"SeaMonkey/") and strstr($agent,"Gecko")) {$br = "SeaMonkey";} echo "Browser: <b>$br</b>, OS: <b>$os</b>"; I found some information from he http://www.zytrax.com/tech/web/browser_ids.htm Is there any better solution for this, or script above is accurate? |