如何从HTML5模板中删除不必要的布局php?

时间:2014-02-19 03:50:03

标签: php html5 responsive-design

我正在修改一个html5模板,其中包含适用于移动设备,智能手机和桌面布局的单独布局。由于桌面布局已经响应,因此我不需要移动和智能手机布局。问题是我无法在不将整个网站关闭的情况下找到如何禁用不需要的布局。这是代码:

的index.php

    <?php 

include "app/config.php";
include "app/detect.php";

if ($page_name=='') {
    include $browser_t.'/index.html';
    }
elseif ($page_name=='index.html') {
    include $browser_t.'/index.html';
    }
elseif ($page_name=='about.html') {
    include $browser_t.'/about.html';
    }
elseif ($page_name=='services.html') {
    include $browser_t.'/services.html';
    }
elseif ($page_name=='contact.html') {
    include $browser_t.'/contact.html';
    }
elseif ($page_name=='404.html') {
    include $browser_t.'/404.html';
    }
elseif ($page_name=='contact-post.html') {
    include $browser_t.'/contact.html';
    include 'app/contact.php';
    }
else
    {
        include $browser_t.'/404.html';
    }

?>

应用程序/ config.php中:

<?php
$current_page_uri = $_SERVER['REQUEST_URI'];
$part_url = explode("/", $current_page_uri);
$page_name = end($part_url);
$email_id = "w3layouts@gmail.com";
?>

应用程序/ detect.php:

<?php
$userBrowser = $_SERVER['HTTP_ACCEPT']; 
if(stristr($userBrowser, 'application/vnd.wap.xhtml+xml')) 
{
$_REQUEST['wap2'] = 1;
}

elseif(stripos($_SERVER['HTTP_USER_AGENT'],"iPod"))
{
$_REQUEST['iphone'] = 1;

}
elseif(stripos($_SERVER['HTTP_USER_AGENT'],"iPhone"))
{
$_REQUEST['iphone'] = 1;

}
elseif(stripos($_SERVER['HTTP_USER_AGENT'],"Android"))
{
$_REQUEST['Android'] = 1;

}
elseif(stripos($_SERVER['HTTP_USER_AGENT'],"IEMobile"))
{
$_REQUEST['IEMobile'] = 1;

}
elseif(stristr($userBrowser, 'DoCoMo/' || 'portalmmm/'))
{
$_REQUEST['imode'] = 1;
}

elseif(stristr($userBrowser, 'text/vnd.wap.wml')) 
{
$_REQUEST['wap'] = 1;
}
elseif(stristr($userBrowser, 'text/html')) 
{
$_REQUEST['html'] = 1;
}


if(!defined('WAP'))
    define('WAP', isset($_REQUEST['wap']) || isset($_REQUEST['wap2']) || isset($_REQUEST['imode'])|| isset($_REQUEST['html'])|| isset($_REQUEST['Android'])|| isset($_REQUEST['iphone'])|| isset($_REQUEST['IEMobile']));

    if (WAP)
{
    define('WIRELESS_PROTOCOL', isset($_REQUEST['wap']) ? 'wap' : (isset($_REQUEST['wap2']) ? 'wap2' : (isset($_REQUEST['iphone']) ? 'iphone' : (isset($_REQUEST['imode']) ? 'imode' : (isset($_REQUEST['IEMobile']) ? 'IEMobile' :(isset($_REQUEST['html']) ? 'html' : (isset($_REQUEST['Android']) ? 'Android' : '')))))));  

if (WIRELESS_PROTOCOL == 'wap')
      {
$browser_t = "mobile";
      }
elseif (WIRELESS_PROTOCOL == 'wap2')
      {


$browser_t = "mobile";


      }
elseif (WIRELESS_PROTOCOL == 'imode')
      {

$browser_t = "mobile";

      }
      elseif (WIRELESS_PROTOCOL == 'iphone')
      {


$browser_t = "smartphone";

      }
      elseif (WIRELESS_PROTOCOL == 'Android')
      {


$browser_t = "smartphone";

      }
       elseif (WIRELESS_PROTOCOL == 'IEMobile')
      {

$browser_t = "smartphone";

      }
      elseif (WIRELESS_PROTOCOL == 'html')
      {

     $mobile_browser = '0';

if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i',
    strtolower($_SERVER['HTTP_USER_AGENT']))){
    $mobile_browser++;
    }

if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or 
    ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))){
    $mobile_browser++;
    }

$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
$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-');

if(in_array($mobile_ua,$mobile_agents)){
    $mobile_browser++;
    }
if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) {
    $mobile_browser++;
    }
        if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'iemobile')>0) {
$mobile_browser++;
}
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
    $mobile_browser=0;
    }


if($mobile_browser>0){
   // do something wap

$browser_t = "mobile";

}
// non-mobile
else
{

$_SESSION['Browser_d'] = "web";
$browser_t = "web";

}
   } else {
   // do something else html

$_SESSION['Browser_d'] = "web";
$browser_t = "web";
   }

      }


    else
    {
$mobile_browser = '0';

if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i',
    strtolower($_SERVER['HTTP_USER_AGENT']))){
    $mobile_browser++;
    }

if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or 
    ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))){
    $mobile_browser++;
    }

$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
$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-');

if(in_array($mobile_ua,$mobile_agents)){
    $mobile_browser++;
    }
    if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'iemobile')>0) {
$mobile_browser++;
}
if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) {
    $mobile_browser++;
    }
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
    $mobile_browser=0;
    }


if($mobile_browser>0){
   // do something wap

$browser_t = "mobile";

}
// non-mobile
else
{
$_SESSION['Browser_d'] = "web";
$browser_t = "web";
}

    }
     ?>

基本上,我需要它来显示“web”文件而不是app / detect.php中的任何其他文件,但是当我尝试评论我认为不需要的时候整个网站都没有出现。< / p>

2 个答案:

答案 0 :(得分:0)

尝试将这些行放在app/detect.php

的末尾
$mobile_browser = 0;
$_SESSION['Browser_d'] = "web";
$browser_t = "web";

这基本上取代了检测桌面浏览器的结果所执行的检测。

答案 1 :(得分:0)

将位于/ web /目录中的所有文件和文件夹放到项目根路径中(您不需要任何其他文件)。

使用您喜欢的编辑器编辑index.html文件。

使用''ex:

搜索并替换每个'网络/'
<link href="web/css/style.css" rel="stylesheet" type="text/css" media="all" />

<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />

对所有html文件执行相同操作。

问候。