Author Topic: สอบถามวิธีการเช็คการเข้าเว็บไซต์ผ่านมือถือ iPad iPhone (iOS) Web Browserค่ะ  (Read 5190 times)

Ralphbut

  • สมาชิกใหม่
  • *
  • Posts: 0
    • View Profile
<?php
   if(preg_match('/android|blackberry|ipad|iphone|ipod/i', $_SERVER['HTTP_USER_AGENT'])){
      header("location:http://m.thaicreate.com/");
      exit;
   }
?>



DOCUMENT_ROOT แสดง Path Root Directory Home
GATEWAY_INTERFACE แสดงค่าอินเทอร์เฟชของ Cgi
HTTP_ACCEPT_LANGUAGE ภาษาที่ใช้
HTTP_CONNECTION สถานภาพการ คอนเน็กต์
HTTP_USER_AGENT แสดงประเภทของโปรแกรมที่เรียกเข้ามา เช่น IE
PATH_INFO แสดงชื่อเอกสาร
PATH_TRANSLATED แสดง Path ของเอกสาร
QUERY_STRING แสดงค่าใน Query String
REMOTE_ADDR แสดงค่า IP Address ของเครื่องที่เข้ามา
REMOTE_PORT แสดง Port เครื่องที่เข้ามา
REQUEST_METHOD แสดงค่ารับส่งว่าเป็น Get หรือ Post
SCRIPT_NAME แสดงชื่อเอกสาร
SERVER_NAME แสดงชื่อ Server
SERVER_PORT แสดง Port ของ Server
SERVER_PROTOCOL แสดง โปรโตคอลของ Server
SERVER_SOFTWARE แสดง โปรแกรมของ Server

Sample

PageServer.php


<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?php
echo "\$_SERVER[\"HTTP_ACCEPT\"] = ".$_SERVER["HTTP_ACCEPT"]."<br>";
echo "\$_SERVER[\"HTTP_ACCEPT_LANGUAGE\"] = ".$_SERVER["HTTP_ACCEPT_LANGUAGE"]."<br>";
echo "\$_SERVER[\"HTTP_ACCEPT_ENCODING\"] = ".$_SERVER["HTTP_ACCEPT_ENCODING"]."<br>";
echo "\$_SERVER[\"HTTP_USER_AGENT\"] = ".$_SERVER["HTTP_USER_AGENT"]."<br>";
echo "\$_SERVER[\"HTTP_HOST\"] = ".$_SERVER["HTTP_HOST"]."<br>";
echo "\$_SERVER[\"HTTP_CONNECTION\"] = ".$_SERVER["HTTP_CONNECTION"]."<br>";
echo "\$_SERVER[\"PATH\"] = ".$_SERVER["PATH"]."<br>";
echo "\$_SERVER[\"SystemRoot\"] = ".$_SERVER["SystemRoot"]."<br>";
echo "\$_SERVER[\"COMSPEC\"] = ".$_SERVER["COMSPEC"]."<br>";
echo "\$_SERVER[\"PATHEXT\"] = ".$_SERVER["PATHEXT"]."<br>";
echo "\$_SERVER[\"WINDIR\"] = ".$_SERVER["WINDIR"]."<br>";
echo "\$_SERVER[\"SERVER_SIGNATURE\"] = ".$_SERVER["SERVER_SIGNATURE"]."<br>";
echo "\$_SERVER[\"SERVER_SOFTWARE\"] = ".$_SERVER["SERVER_SOFTWARE"]."<br>";
echo "\$_SERVER[\"SERVER_NAME\"] = ".$_SERVER["SERVER_NAME"]."<br>";
echo "\$_SERVER[\"SERVER_ADDR\"] = ".$_SERVER["SERVER_ADDR"]."<br>";
echo "\$_SERVER[\"SERVER_PORT\"] = ".$_SERVER["SERVER_PORT"]."<br>";
echo "\$_SERVER[\"REMOTE_ADDR\"] = ".$_SERVER["REMOTE_ADDR"]."<br>";
echo "\$_SERVER[\"DOCUMENT_ROOT\"] = ".$_SERVER["DOCUMENT_ROOT"]."<br>";
echo "\$_SERVER[\"SERVER_ADMIN\"] = ".$_SERVER["SERVER_ADMIN"]."<br>";
echo "\$_SERVER[\"SCRIPT_FILENAME\"] = ".$_SERVER["SCRIPT_FILENAME"]."<br>";
echo "\$_SERVER[\"REMOTE_PORT\"] = ".$_SERVER["REMOTE_PORT"]."<br>";
echo "\$_SERVER[\"GATEWAY_INTERFACE\"] = ".$_SERVER["GATEWAY_INTERFACE"]."<br>";
echo "\$_SERVER[\"SERVER_PROTOCOL\"] = ".$_SERVER["SERVER_PROTOCOL"]."<br>";
echo "\$_SERVER[\"REQUEST_METHOD\"] = ".$_SERVER["REQUEST_METHOD"]."<br>";
echo "\$_SERVER[\"QUERY_STRING\"] = ".$_SERVER["QUERY_STRING"]."<br>";
echo "\$_SERVER[\"REQUEST_URI\"] = ".$_SERVER["REQUEST_URI"]."<br>";
echo "\$_SERVER[\"SCRIPT_NAME\"] = ".$_SERVER["SCRIPT_NAME"]."<br>";
echo "\$_SERVER[\"PHP_SELF\"] = ".$_SERVER["PHP_SELF"]."<br>";
echo "\$_SERVER[\"REQUEST_TIME\"] = ".$_SERVER["REQUEST_TIME"]."<br>";
echo "\$_SERVER[\"argv\"] = ".$_SERVER["argv"]."<br>";
echo "\$_SERVER[\"argc\"] = ".$_SERVER["argc"]."<br>";
?>
</body>
</html>



<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?php
echo "\$_SERVER[\"HTTP_ACCEPT\"] = ".$_SERVER["HTTP_ACCEPT"]."<br>";
echo "\$_SERVER[\"HTTP_ACCEPT_LANGUAGE\"] = ".$_SERVER["HTTP_ACCEPT_LANGUAGE"]."<br>";
echo "\$_SERVER[\"HTTP_ACCEPT_ENCODING\"] = ".$_SERVER["HTTP_ACCEPT_ENCODING"]."<br>";
echo "\$_SERVER[\"HTTP_USER_AGENT\"] = ".$_SERVER["HTTP_USER_AGENT"]."<br>";
echo "\$_SERVER[\"HTTP_HOST\"] = ".$_SERVER["HTTP_HOST"]."<br>";
echo "\$_SERVER[\"HTTP_CONNECTION\"] = ".$_SERVER["HTTP_CONNECTION"]."<br>";
echo "\$_SERVER[\"PATH\"] = ".$_SERVER["PATH"]."<br>";
echo "\$_SERVER[\"SystemRoot\"] = ".$_SERVER["SystemRoot"]."<br>";
echo "\$_SERVER[\"COMSPEC\"] = ".$_SERVER["COMSPEC"]."<br>";
echo "\$_SERVER[\"PATHEXT\"] = ".$_SERVER["PATHEXT"]."<br>";
echo "\$_SERVER[\"WINDIR\"] = ".$_SERVER["WINDIR"]."<br>";
echo "\$_SERVER[\"SERVER_SIGNATURE\"] = ".$_SERVER["SERVER_SIGNATURE"]."<br>";
echo "\$_SERVER[\"SERVER_SOFTWARE\"] = ".$_SERVER["SERVER_SOFTWARE"]."<br>";
echo "\$_SERVER[\"SERVER_NAME\"] = ".$_SERVER["SERVER_NAME"]."<br>";
echo "\$_SERVER[\"SERVER_ADDR\"] = ".$_SERVER["SERVER_ADDR"]."<br>";
echo "\$_SERVER[\"SERVER_PORT\"] = ".$_SERVER["SERVER_PORT"]."<br>";
echo "\$_SERVER[\"REMOTE_ADDR\"] = ".$_SERVER["REMOTE_ADDR"]."<br>";
echo "\$_SERVER[\"DOCUMENT_ROOT\"] = ".$_SERVER["DOCUMENT_ROOT"]."<br>";
echo "\$_SERVER[\"SERVER_ADMIN\"] = ".$_SERVER["SERVER_ADMIN"]."<br>";
echo "\$_SERVER[\"SCRIPT_FILENAME\"] = ".$_SERVER["SCRIPT_FILENAME"]."<br>";
echo "\$_SERVER[\"REMOTE_PORT\"] = ".$_SERVER["REMOTE_PORT"]."<br>";
echo "\$_SERVER[\"GATEWAY_INTERFACE\"] = ".$_SERVER["GATEWAY_INTERFACE"]."<br>";
echo "\$_SERVER[\"SERVER_PROTOCOL\"] = ".$_SERVER["SERVER_PROTOCOL"]."<br>";
echo "\$_SERVER[\"REQUEST_METHOD\"] = ".$_SERVER["REQUEST_METHOD"]."<br>";
echo "\$_SERVER[\"QUERY_STRING\"] = ".$_SERVER["QUERY_STRING"]."<br>";
echo "\$_SERVER[\"REQUEST_URI\"] = ".$_SERVER["REQUEST_URI"]."<br>";
echo "\$_SERVER[\"SCRIPT_NAME\"] = ".$_SERVER["SCRIPT_NAME"]."<br>";
echo "\$_SERVER[\"PHP_SELF\"] = ".$_SERVER["PHP_SELF"]."<br>";
echo "\$_SERVER[\"REQUEST_TIME\"] = ".$_SERVER["REQUEST_TIME"]."<br>";
echo "\$_SERVER[\"argv\"] = ".$_SERVER["argv"]."<br>";
echo "\$_SERVER[\"argc\"] = ".$_SERVER["argc"]."<br>";
?>
</body>
</html>






Ralphbut

  • สมาชิกใหม่
  • *
  • Posts: 0
    • View Profile
function detect_mobile()
{
    if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
        return true;

    else
        return false;
}

$mobile = detect_mobile();

if($mobile === true){
    header('Location: http://www.domain-name.com/sp/');
}

Ralphbut

  • สมาชิกใหม่
  • *
  • Posts: 0
    • View Profile
<?php
if(isMobileCheck()){
   echo "Browse from mobile phone";
}else{
    echo "Browse from Other";
}
?>

Ralphbut

  • สมาชิกใหม่
  • *
  • Posts: 0
    • View Profile
<?php
function isMobileCheck(){
   $isMobile = false;
   $op = strtolower($_SERVER['HTTP_X_OPERAMINI_PHONE']);
   $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
   $ac = strtolower($_SERVER['HTTP_ACCEPT']);
   $ip = $_SERVER['REMOTE_ADDR'];
   
   $isMobile = strpos($ac, 'application/vnd.wap.xhtml+xml') !== false
         || $op != ''
         || strpos($ua, 'sony') !== false
         || strpos($ua, 'symbian') !== false
         || strpos($ua, 'nokia') !== false
         || strpos($ua, 'samsung') !== false
         || strpos($ua, 'mobile') !== false
         || strpos($ua, 'windows ce') !== false
         || strpos($ua, 'epoc') !== false
         || strpos($ua, 'opera mini') !== false
         || strpos($ua, 'nitro') !== false
         || strpos($ua, 'j2me') !== false
         || strpos($ua, 'midp-') !== false
         || strpos($ua, 'cldc-') !== false
         || strpos($ua, 'netfront') !== false
         || strpos($ua, 'mot') !== false
         || strpos($ua, 'up.browser') !== false
         || strpos($ua, 'up.link') !== false
         || strpos($ua, 'audiovox') !== false
         || strpos($ua, 'blackberry') !== false
         || strpos($ua, 'ericsson,') !== false
         || strpos($ua, 'panasonic') !== false
         || strpos($ua, 'philips') !== false
         || strpos($ua, 'sanyo') !== false
         || strpos($ua, 'sharp') !== false
         || strpos($ua, 'sie-') !== false
         || strpos($ua, 'portalmmm') !== false
         || strpos($ua, 'blazer') !== false
         || strpos($ua, 'avantgo') !== false
         || strpos($ua, 'danger') !== false
         || strpos($ua, 'palm') !== false
         || strpos($ua, 'series60') !== false
         || strpos($ua, 'palmsource') !== false
         || strpos($ua, 'pocketpc') !== false
         || strpos($ua, 'smartphone') !== false
         || strpos($ua, 'rover') !== false
         || strpos($ua, 'ipaq') !== false
         || strpos($ua, 'au-mic,') !== false
         || strpos($ua, 'alcatel') !== false
         || strpos($ua, 'ericy') !== false
         || strpos($ua, 'up.link') !== false
         || strpos($ua, 'vodafone/') !== false
         || strpos($ua, 'wap1.') !== false
         || strpos($ua, 'wap2.') !== false;
      return $isMobile;   
}
?>