叶测试 发布的文章

织梦dedecms判断手机进行跳转

推荐:
uaredirect.js

function uaredirect(f){try{if(document.getElementById("bdmark")!=null){return}var b=false;if(arguments[1]){var e=window.location.host;var a=window.location.href;if(isSubdomain(arguments[1],e)==1){f=f+"/#m/"+a;b=true}else{if(isSubdomain(arguments[1],e)==2){f=f+"/#m/"+a;b=true}else{f=a;b=false}}}else{b=true}if(b){var c=window.location.hash;if(!c.match("fromapp")){if((navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i))){location.replace(f)}}}}catch(d){}}function isSubdomain(c,d){this.getdomain=function(f){var e=f.indexOf("://");if(e>0){var h=f.substr(e+3)}else{var h=f}var g=/^www\./;if(g.test(h)){h=h.substr(4)}return h};if(c==d){return 1}else{var c=this.getdomain(c);var b=this.getdomain(d);if(c==b){return 1}else{c=c.replace(".","\\.");var a=new RegExp("\\."+c+"$");if(b.match(a)){return 2}else{return 0}}}};

栏目页跳转:uaredirect("/m/list.php?tid={dede:field.id /}");
首页跳转:uaredirect("/m");
文章页跳转:uaredirect("/m/view.php?aid={dede:field.id /}");

index.php添加:
//判断手机登录

function ismobile() {
    // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
    if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
        return true;

    //此条摘自TPM智能切换模板引擎,适合TPM开发
    if(isset ($_SERVER['HTTP_CLIENT']) &&'PhoneClient'==$_SERVER['HTTP_CLIENT'])
        return true;
    //如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
    if (isset ($_SERVER['HTTP_VIA']))
        //找不到为flase,否则为true
        return stristr($_SERVER['HTTP_VIA'], 'wap') ? true : false;
    //判断手机发送的客户端标志,兼容性有待提高
    if (isset ($_SERVER['HTTP_USER_AGENT'])) {
        $clientkeywords = array(
            'nokia','sony','ericsson','mot','samsung','htc','sgh','lg','sharp','sie-','philips','panasonic','alcatel','lenovo','iphone','ipod','blackberry','meizu','android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile'
        );
        //从HTTP_USER_AGENT中查找手机浏览器的关键字
        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
            return true;
        }
    }
    //协议法,因为有可能不准确,放到最后判断
    if (isset ($_SERVER['HTTP_ACCEPT'])) {
        // 如果只支持wml并且不支持html那一定是移动设备
        // 如果支持wml和html但是wml在html之前则是移动设备
        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
            return true;
        }
    }
    return false;
}

if (isMobile()){
    header('Location:m/index.php');
}else{
    //自动生成HTML版
    if(isset($_GET['upcache']) || !file_exists('index.html'))
    {
        require_once (dirname(__FILE__) . "/include/common.inc.php");
        require_once DEDEINC."/arc.partview.class.php";
        $GLOBALS['_arclistEnv'] = 'index';
        $row = $dsql->GetOne("Select * From `#@__homepageset`");
        $row['templet'] = MfTemplet($row['templet']);
        $pv = new PartView();
        $pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $row['templet']);
        $row['showmod'] = isset($row['showmod'])? $row['showmod'] : 0;
        if ($row['showmod'] == 1)
        {
            $pv->SaveToHtml(dirname(__FILE__).'/index.html');
            include(dirname(__FILE__).'/index.html');
            exit();
        } else { 
            $pv->Display();
            exit();
        }
    }
    else
    {
        header('HTTP/1.1 301 Moved Permanently');
        header('Location:index.html');
    }

}

JS跳转:

function mobileRedirect(murl){
    try {
        if(document.getElementById("bdmark") != null){
        return;
    }
            
    var urlhash = window.location.hash;
        if (!urlhash.match("fromapp")){
            if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad|Symbia)/i))) {
            location.replace(murl);
            }
        }
    } catch(err){}
}
mobileRedirect("/m/");

html2canvas网页截图导出为图片并用JS下载

html2canvas是一个相当不错的JavaScript类库,它使用了html5和css3的一些新功能特性,实现了在客户端对网页进行截图的功 能。html2canvas通过获取页面的DOM和元素的样式信息,并将其渲染成canvas图片,从而实现给页面截图的功能。

它不需要来自服务器任何渲染,整张图片都是在客户端浏览器创建。当浏览器不支持Canvas时,将采用Flashcanvas或 ExplorerCanvas技术代替实现。以下浏览器能够很好的支持该脚本:Firefox 3.5+, Google Chrome, Opera新的版本, IE9以上的浏览器。

- 阅读剩余部分 -

jquery禁用右键、文本选择功能、复制的代码

//禁用右键、文本选择功能、复制按键
$(document).bind("contextmenu",function(){return false;});
$(document).bind("selectstart",function(){return false;});
$(document).keydown(function(){return key(arguments[0])});
//按键时提示警告
function key(e){
var keynum;
if(window.event){
keynum = e.keyCode; // IE
}else if(e.which){
keynum = e.which; // Netscape/Firefox/Opera
}
if(keynum == 17){
alert(“禁止复制内容!”);
return false;
}
}
//禁用右键、文本选择功能、复制按键
    $(document).bind("contextmenu",function(){return false;});
    $(document).bind("selectstart",function(){return false;});
    $(document).keydown(function(){return key(arguments[0])}); 
 
 //按键时提示警告
       function key(e){
            var keynum;
            if(window.event) // IE
              {
                keynum = e.keyCode;
              }
            else if(e.which) // Netscape/Firefox/Opera
              {
                keynum = e.which;
              }
            if(keynum == 17){ alert("禁止复制内容!");return false;}
        }
 
 
<script>  
//屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键     
function   document.oncontextmenu(){event.returnValue=false;}//屏蔽鼠标右键   
function   window.onhelp(){return false}       //屏蔽F1帮助   
function   document.onkeydown(){   
    if((window.event.altKey)&&   
      ((window.event.keyCode==37)||            //屏蔽Alt+方向键←   
      (window.event.keyCode==39))){            //屏蔽Alt+方向键→
           alert("不准你使用ALT+方向键前进或后退网页!");   
           event.returnValue=false;    
      }         if((event.keyCode==8)||                    //屏蔽退格删除键    
      (event.keyCode==116)||                   //屏蔽F5刷新键   
      (event.ctrlKey && event.keyCode==82)){   //Ctrl+R   
           event.keyCode=0;   
           event.returnValue=false;   
      }   
      if(event.keyCode==122){event.keyCode=0;event.returnValue=false;}    //屏蔽F11   
      if(event.ctrlKey && event.keyCode==78)event.returnValue=false;      //屏蔽Ctrl+n   
      if(event.shiftKey && event.keyCode==121)event.returnValue=false;    //屏蔽shift+F10   
      if(window.event.srcElement.tagName=="A" && window.event.shiftKey)     
         window.event.returnValue=false;       //屏蔽shift加鼠标左键新开一网页   
      if((window.event.altKey)&&(window.event.keyCode==115)){             //屏蔽Alt+F4    
         window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");   
         return false;   
      }   
  }   
</script>

PHPExcel读取EXCEL中的图片并保存到本地

项目中需要读取php中图片保存到服务器同时将图片地址写入数据库,phpexcel示例代码如下:

<?php   
ini_set("display_errors",1);  
   
include 'PHPExcel.php';  
include 'PHPExcel/IOFactory.php';  
   
define('EXCEL_EXTENSION_2003', "xls");  
define('EXCEL_EXTENSION_2007', "xlsx");  
   
   
$fileName2003 = "file.xls";  
$fileName2007 = "file.xlsx";  
   
$fileName = $fileName2003;  
//$fileName = $fileName2007;  
   
if(getExtendFileName($fileName) == EXCEL_EXTENSION_2003)  
{  
    $reader = PHPExcel_IOFactory::createReader('Excel5');  
}  
else if(getExtendFileName($fileName) == EXCEL_EXTENSION_2007)  
{  
    $reader = new PHPExcel_Reader_Excel2007();  
}  

$PHPExcel = $reader->load($fileName);  
$worksheet = $PHPExcel->getActiveSheet();  
$imageInfo = extractImageFromWorksheet($worksheet,"savepath/");  

print_r($imageInfo);

/**
 * 检测文件类型
 *
 * @param      <type>  $file_name  The file name
 *
 * @return     <type>  The extend file name.
 */
function getExtendFileName($file_name) {  
    $extend = pathinfo($file_name);
    $extend = strtolower($extend["extension"]);
    return $extend;
}  

/**
 * 获取图片
 *
 * @param      <type>  $worksheet  The worksheet
 * @param      <type>  $basePath   The base path
 *
 * @return     array   ( description_of_the_return_value )
 */
function extractImageFromWorksheet($worksheet, $basePath){  
    $result = array();  
    $imageFileName = "";  
    foreach ($worksheet->getDrawingCollection() as $drawing) {  
        $xy=$drawing->getCoordinates();  
        $path = $basePath;  
        // for xlsx  
        if ($drawing instanceof PHPExcel_Worksheet_Drawing) {  
            $filename = $drawing->getPath();  
            $imageFileName = $drawing->getIndexedFilename();  
            $path = $path . $drawing->getIndexedFilename();  
            copy($filename, $path);  
            $result[$xy] = $path;  
        // for xls  
        } else if ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) {  
            $image = $drawing->getImageResource();  
            $renderingFunction = $drawing->getRenderingFunction();  
            switch ($renderingFunction) {  
                case PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG:  
                    $imageFileName = $drawing->getIndexedFilename();  
                    $path = $path . $drawing->getIndexedFilename();  
                    imagejpeg($image, $path);  
                    break;  
                case PHPExcel_Worksheet_MemoryDrawing::RENDERING_GIF:  
                    $imageFileName = $drawing->getIndexedFilename();  
                    $path = $path . $drawing->getIndexedFilename();  
                    imagegif($image, $path);  
                    break;  
                case PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG:  
                    $imageFileName = $drawing->getIndexedFilename();  
                    $path = $path . $drawing->getIndexedFilename();  
                    imagegif($image, $path);  
                    break;
                case PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT:  
                    $imageFileName = $drawing->getIndexedFilename();  
                    $path = $path . $drawing->getIndexedFilename();  
                    imagegif($image, $path);  
                    break;
            }
            $result[$xy] = $imageFileName;
        }
    }
    return $result;
}

网站屏蔽指定省市 禁止IP查看网站

<?php 
    //屏蔽北上广
    $ip = get_client_ip();
    // $url = "http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
    $url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=".$ip;
    $data = https_request($url);
    $data = json_decode($data, true);

    $region = $data['province'];
    if($region == '广东' || $region == '北京' || $region == '上海'){
        header("Content-type: text/html; charset=utf-8");
        echo "<h1>网站升级中</h1>";
        die;
    }

    /**
     * 获取访客IP地址
     *
     * @param      integer  $type   The type
     * @param      boolean  $adv    The advance
     *
     * @return     array    The client ip.
     */
    function get_client_ip($type = 0,$adv=false) {
        $type       =  $type ? 1 : 0;
        static $ip  =   NULL;
        if ($ip !== NULL) return $ip[$type];
        if($adv){
            if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                $arr    =   explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
                $pos    =   array_search('unknown',$arr);
                if(false !== $pos) unset($arr[$pos]);
                $ip     =   trim($arr[0]);
            }elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
                $ip     =   $_SERVER['HTTP_CLIENT_IP'];
            }elseif (isset($_SERVER['REMOTE_ADDR'])) {
                $ip     =   $_SERVER['REMOTE_ADDR'];
            }
        }elseif (isset($_SERVER['REMOTE_ADDR'])) {
            $ip     =   $_SERVER['REMOTE_ADDR'];
        }
        // IP地址合法验证
        $long = sprintf("%u",ip2long($ip));
        $ip   = $long ? array($ip, $long) : array('0.0.0.0', 0);
        return $ip[$type];
    }

    /**
     * 获取接口数据
     *
     * @param      <type>  $url    The url
     *
     * @return     <type>  ( description_of_the_return_value )
     */
    function https_request($url){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }