php 广告加载类

2023-05-16

php 广告加载类,支持异步与同步加载。需要使用Jquery

ADLoader.class.php

<?php
/** 广告加载管理类
*   Date:   2013-08-04
*   Author: fdipzone
*   Ver:    1.0
*
*   Func:
*   public  load         加载广告集合
*   public  setConfig    广告配置
*   private getAds       根据channel创建广告集合
*   private genZoneId    zoneid base64_encode 处理
*   private genHtml      生成广告html
*   private checkBrowser 检查是否需要同步加载的浏览器
*/

class ADLoader{ // class start

    private static $_ads = array();     // 广告集合
    private static $_step = 300;        // 广告加载间隔
    private static $_async = true;      // 是否异步加载
    private static $_config = array();  // 广告设置文件
    private static $_jsclass = null;    // 广告JS class


    /** 加载广告集合
    * @param String  $channel 栏目,对应config文件
    * @param int     $step    广告加载间隔
    * @param boolean $async   是否异步加载
    */
    public static function load($channel='', $step='', $async=''){
        if(isset($step) && is_numeric($step) && $step>0){
            self::$_step = $step;
        }

        if(isset($async) && is_bool($async)){
            self::$_async = $async;
        }

        // 判断浏览器,如IE强制使用同步加载
        if(!self::checkBrowser()){
            self::$_async = false;
        }

        self::getAds($channel);
        self::genZoneId();

        return self::genHtml();
    }


    /** 设置config
    * @param String $config  广告配置
    * @param String $jsclass js class文件路径
    */
    public static function setConfig($config=array(), $jsclass=''){
        self::$_config = $config;
        self::$_jsclass = $jsclass;
    }


    /** 根据channel创建广告集合
    * @param String $channel 栏目
    */
    private static function getAds($channel=''){
        $AD_Config = self::$_config;
        if($AD_Config!=null){
            self::$_ads = isset($AD_Config[$channel])? $AD_Config[$channel] : $AD_Config['default'];
        }
    }


    /** zoneid base64_encode 处理 */
    private static function genZoneId(){

        // 同步加载广告不需要处理zoneid
        if(!self::$_async){
            return ;
        }

        $ads = self::$_ads;
        for($i=0,$len=count($ads); $i<$len; $i++){
            if(isset($ads[$i]['zoneId'])){
                $ads[$i]['zoneId'] = base64_encode('var zoneid='.$ads[$i]['zoneId'].';');
            }
        }
        self::$_ads = $ads;
    }


    /** 生成广告html */
    private static function genHtml(){
        $ads = self::$_ads;
        $html = array();
        if(self::$_jsclass!=null && $ads){
            array_push($html, '<script type="text/javascript" src="'.self::$_jsclass.'"></script>');

			// 同步需要预先加载
            if(!self::$_async){
				foreach($ads as $ad){
					array_push($html, '<div id="'.$ad['domId'].'_container" style="display:none">');
					array_push($html, '<script type="text/javascript">');
					array_push($html, 'ADLoader.preload('.json_encode($ad).');');
					array_push($html, '</script>');
					array_push($html, '</div>');
				}
            }

			array_push($html, '<script type="text/javascript">');
            array_push($html, 'var ads='.json_encode($ads).';');
            array_push($html, '$(document).ready(function(){ ADLoader.load(ads, '.self::$_step.', '.intval(self::$_async).'); });');
            array_push($html, '</script>');
        }
        return implode("\r\n", $html);
    }


    /** 判断是否需要强制同步加载的浏览器 */
    private static function checkBrowser(){
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
        if(strstr($user_agent,'MSIE')!=''){
            return false;
        }
        return true;
    }

} // class end

?>

ADConfig.php

<?php
/** 广告配置文件 **/

return array(

    'case_openx' => array(
        array(
            'type' => 'openx',
            'domId' => 'ad_728x90',
            'zoneId' => 452
        ),
        array(
            'type' => 'openx',
            'domId' => 'ad_300x250',
            'zoneId' => 449
        ),
        array(
            'type' => 'openx',
            'domId' => 'ad_l2_300x250',
            'zoneId' => 394
        ),
    ),

    'case_url' => array(
        array(
            'type' => 'url',
            'domId' => 'ad_728x90',
            'url' => 'adurl.php?zoneid=452'
        ),
        array(
            'type' => 'url',
            'domId' => 'ad_300x250',
            'url' => 'adurl.php?zoneid=449'
        ),
        array(
            'type' => 'url',
            'domId' => 'ad_l2_300x250',
            'url' => 'adurl.php?zoneid=394'
        )
    ),

    'case_sync_openx' => array(
        array(
            'type' => 'openx',
            'domId' => 'ad_728x90',
            'zoneId' => 452
        ),
        array(
            'type' => 'openx',
            'domId' => 'ad_300x250',
            'zoneId' => 449
        ),
        array(
            'type' => 'openx',
            'domId' => 'ad_l2_300x250',
            'zoneId' => 394
        ),
    ),

    'default' => array(
        array(
            'type' => 'openx',
            'domId' => 'ad_728x90',
            'zoneId' => 452
        ),
        array(
            'type' => 'openx',
            'domId' => 'ad_300x250',
            'zoneId' => 449
        ),
        array(
            'type' => 'openx',
            'domId' => 'ad_l2_300x250',
            'zoneId' => 394
        ),
    ),

);

?>
ADLoader.js
/** 异步加载广告
*   Date:   2013-08-04
*   Author: fdipzone
*   Ver:    1.0
*/
var ADLoader = (function(){

    var _ads = [],     // 广告集合
        _step = 300,   // 广告加载间隔
        _async = true, // 是否异步加载
        _loaded = 0;   // 已经加载的广告数

    
    /** loadAd 循环加载广告
    * @param int c 第几个广告
    */
    function loadAD(c){
        if(_loaded>=_ads.length){
            return ;
        }

        if($('#'+_ads[c].domId).length>0){ // 判断dom是否存在

            if(_async){ // 异步执行

                crapLoader.loadScript(getScript(_ads[c]), _ads[c].domId, {
                    success: function(){
                        completeAd();
                    }
                });
            
            }else{ // 将同步加载的广告显示

                var ad_container = $('#'+_ads[c].domId+'_container');
                ad_container.find('embed').attr('wmode','transparent').end().find('object').each(function(k, v){
                    v.wmode = 'transparent'; // 将flash变透明
                });
                $('#'+_ads[c].domId)[0].appendChild(ad_container[0]);
                ad_container.show();
                
                completeAd();

            }

        }else{ // dom不存在
            completeAd();
        }
    }

    /** 加载完广告后处理 */
    function completeAd(){
        _loaded ++;
        setTimeout(function(){
            loadAD(_loaded);
        }, _step);        
    }

    /** 获取广告
    * @param Array ad 广告参数
    */
    function getScript(ad){
        var ret = null;

        switch(ad.type){
            case 'openx':  // openx code ad
                ret = 'data:text/javascript;base64,' + ad.zoneId + 'dmFyIG0zX3UgPSAobG9jYXRpb24ucHJvdG9jb2w9PSdodHRwczonPydodHRwczovL2Fkcy5ubWcuY29tLmhrL3d3dy9kZWxpdmVyeS9hanMucGhwJzonaHR0cDovL2Fkcy5ubWcuY29tLmhrL3d3dy9kZWxpdmVyeS9hanMucGhwJyk7CnZhciBtM19yID0gTWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpKjk5OTk5OTk5OTk5KTsKaWYgKCFkb2N1bWVudC5NQVhfdXNlZCkgZG9jdW1lbnQuTUFYX3VzZWQgPSAnLCc7CmRvY3VtZW50LndyaXRlICgiPHNjciIrImlwdCB0eXBlPSd0ZXh0L2phdmFzY3JpcHQnIHNyYz0nIittM191KTsKZG9jdW1lbnQud3JpdGUgKCI/em9uZWlkPSIgKyB6b25laWQpOwpkb2N1bWVudC53cml0ZSAoJyZhbXA7Y2I9JyArIG0zX3IpOwppZiAoZG9jdW1lbnQuTUFYX3VzZWQgIT0gJywnKSBkb2N1bWVudC53cml0ZSAoIiZhbXA7ZXhjbHVkZT0iICsgZG9jdW1lbnQuTUFYX3VzZWQpOwpkb2N1bWVudC53cml0ZSAoZG9jdW1lbnQuY2hhcnNldCA/ICcmYW1wO2NoYXJzZXQ9Jytkb2N1bWVudC5jaGFyc2V0IDogKGRvY3VtZW50LmNoYXJhY3RlclNldCA/ICcmYW1wO2NoYXJzZXQ9Jytkb2N1bWVudC5jaGFyYWN0ZXJTZXQgOiAnJykpOwpkb2N1bWVudC53cml0ZSAoIiZhbXA7bG9jPSIgKyBlc2NhcGUod2luZG93LmxvY2F0aW9uKSk7CmlmIChkb2N1bWVudC5yZWZlcnJlcikgZG9jdW1lbnQud3JpdGUgKCImYW1wO3JlZmVyZXI9IiArIGVzY2FwZShkb2N1bWVudC5yZWZlcnJlcikpOwppZiAoZG9jdW1lbnQuY29udGV4dCkgZG9jdW1lbnQud3JpdGUgKCImY29udGV4dD0iICsgZXNjYXBlKGRvY3VtZW50LmNvbnRleHQpKTsKaWYgKGRvY3VtZW50Lm1tbV9mbykgZG9jdW1lbnQud3JpdGUgKCImYW1wO21tbV9mbz0xIik7CmRvY3VtZW50LndyaXRlICgiJz48XC9zY3IiKyJpcHQ+Iik7';
                break;
           
            case 'url': // url ad
                ret = ad.url;
                break;
        }

        return ret;
    }

    /** 同步加载广告
    * @param Array ad 广告参数
    */
    function writeAd(ad){
        switch(ad.type){
            case 'openx':
                var m3_u = (location.protocol=='https:'?'https://ads.nmg.com.hk/www/delivery/ajs.php':'http://ads.nmg.com.hk/www/delivery/ajs.php');
                var m3_r = Math.floor(Math.random()*99999999999);
                if (!document.MAX_used) document.MAX_used = ',';
                document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
                document.write ("?zoneid=" + ad.zoneId);
                document.write ('&cb=' + m3_r);
                if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
                document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
                document.write ("&loc=" + escape(window.location));
                if (document.referrer) document.write ("&referer=" + escape(document.referrer));
                if (document.context) document.write ("&context=" + escape(document.context));
                if (document.mmm_fo) document.write ("&mmm_fo=1");
                document.write ("'><\/scr"+"ipt>");
                break;
             case 'url':
                document.write ('<script type="text/javascript" src="' + ad.url + '"></script>');
                break;
        }
    }


    obj = {

        /** 加载广告
        * @param Array   ads   广告集合
        * @param int     step  广告加载间隔
        * @param boolean async true:异步加载 false:同步加载
        */
        load: function(ads, step, async){
            _ads = ads;

            if(typeof(step)!='undefined'){
                _step = step;
            }

            if(typeof(async)!='undefined'){
                _async = async;
            }

            loadAD(_loaded);
        },

        /** 预加载广告 */
        preload: function(ad){
            if($('#'+ad.domId).length>0){   // 判断dom是否存在
                writeAd(ad);
            }
        }

    }

    return obj;

}());


/* crapLoader */
var crapLoader = (function() {
    
    var isHijacked = false,
        queue = [],
        inputBuffer = [],
        writeBuffer = {},
        loading = 0,
        elementCache = {},
        returnedElements = [],
        splitScriptsRegex = /(<script[\s\S]*?<\/script>)/gim,
        globalOptions = {
            autoRelease: true,
            parallel: true,
            debug: false
        },
        defaultOptions = {
            charset: undefined,
            success: undefined,
            func: undefined,
            src: undefined,
            timeout: 3000
        },publ,
        head = document.getElementsByTagName("head")[0] || document.documentElement,
        support = {
            scriptOnloadTriggeredAccurately: false,
            splitWithCapturingParentheses: ("abc".split(/(b)/)[1]==="b")
        };


    
    function checkQueue () {
        if(queue.length) {
            loadScript( queue.shift() );
        } else if(loading === 0 && globalOptions.autoRelease) {
            debug("Queue is empty. Auto-releasing.");
            publ.release();
        }
    }

    function checkWriteBuffer (obj) {
        var buffer = writeBuffer[obj.domId],
            returnedEl;

        if(buffer && buffer.length) {
            writeHtml( buffer.shift(), obj );

        } else {
            while (returnedElements.length > 0) {
                returnedEl = returnedElements.pop();
                var id = returnedEl.id;
                var elInDoc = getElementById(id);
                if (!elInDoc) { continue; }
                var parent = elInDoc.parentNode;
                elInDoc.id = id + "__tmp";
                parent.insertBefore(returnedEl, elInDoc);
                parent.removeChild(elInDoc);
            }
            finished(obj);
        }
    }

    function debug (message, obj) {
        if(!globalOptions.debug || !window.console) { return; }
        var objExtra = "";
        if(obj) {
            objExtra = "#"+obj.domId+" ";
            var depth = obj.depth;
            while(depth--) { objExtra += "    "; }
        }
        console.log("crapLoader " + objExtra + message);
    }

    function extend (t, s) {
        var k;
        if(!s) { return t; }
        for(k in s) {
            t[k] = s[k];
        }
        return t;
    }

    function finished (obj) {
        if(obj.success && typeof obj.success === "function") {
            obj.success.call( document.getElementById(obj.domId) );
        }

        checkQueue();
    }

    function flush (obj) {
        var domId = obj.domId,
           outputFromScript,
           htmlPartArray;

        outputFromScript = stripNoScript( inputBuffer.join("") );
        inputBuffer = [];

        htmlPartArray = separateScriptsFromHtml( outputFromScript );

        if(!writeBuffer[domId]) {
            writeBuffer[domId] = htmlPartArray;
        } else {
            Array.prototype.unshift.apply(writeBuffer[domId], htmlPartArray);
        }
        checkWriteBuffer(obj);
    }

    function getCachedElById (domId) {
        return elementCache[domId] || (elementCache[domId] = document.getElementById(domId));
    }

    function getElementById (domId) {
        return ( publ.orgGetElementById.call ?
            publ.orgGetElementById.call(document, domId) :
            publ.orgGetElementById(domId) );
    }

    function getElementByIdReplacement (domId) {
        var el = getElementById(domId),
            html, frag, div, found;

        function traverseForElById(domId, el) {
            var children = el.children, i, l, child;
            if(children && children.length) {
                for(i=0,l=children.length; i<l; i++) {
                    child = children[i];
                    if(child.id && child.id === domId) { return child; }
                    if(child.children && child.children.length) {
                        var tmp = traverseForElById(domId, child);
                        if (tmp) return tmp;
                    }
                }
            }
        }

        function searchForAlreadyReturnedEl(domId) {
            var i, l, returnedEl;
            for(i=0,l=returnedElements.length; i<l; i++) {
                returnedEl = returnedElements[i];
                if(returnedEl.id === domId) { return returnedEl; }
            }
        }

        if(el) { return el; }

        if (returnedElements.length) {
            found = searchForAlreadyReturnedEl(domId);
            if (found) {
                return found;
            }
        }

        if(inputBuffer.length) {
            html = inputBuffer.join("");
            frag = document.createDocumentFragment();
            div = document.createElement("div");
            div.innerHTML = html;
            frag.appendChild(div);
            found = traverseForElById(domId, div);
            if (found) {
                returnedElements.push(found);
            }
            return found;
        }
    }

    var globalEval = (function () {
        return (window.execScript ? function(code, language) {
            window.execScript(code, language || "JavaScript");
        } : function(code, language) {
            if(language && !/^javascript/i.test(language)) { return; }
            window.eval.call(window, code);
        });
    }());

    function isScript (html) {
        return html.toLowerCase().indexOf("<script") === 0;
    }

    function runFunc (obj) {
        obj.func();
        obj.depth++;
        flush(obj);
    }

    function loadScript (obj) {
        loading++;
        // async loading code from jQuery
        var script = document.createElement("script");
        if(obj.type) { script.type = obj.type; }
        if(obj.charset) { script.charset = obj.charset; }
        if(obj.language) { script.language = obj.language; }

        logScript(obj);

        var done = false;
        // Attach handlers for all browsers
        script.onload = script.onreadystatechange = function() {
            loading--;
            script.loaded = true;
            if ( !done && (!this.readyState ||
                    this.readyState === "loaded" || this.readyState === "complete") ) {
                done = true;
                script.onload = script.onreadystatechange = null;
                debug("onload " + obj.src, obj);
                flush(obj);
            }
        };

        script.loaded = false;
        script.src = obj.src;
        obj.depth++;

        // Use insertBefore instead of appendChild  to circumvent an IE6 bug.
        // This arises when a base node is used (#2709 and #4378).
        head.insertBefore( script, head.firstChild );
        setTimeout(function() {
            if(!script.loaded) { throw new Error("SCRIPT NOT LOADED: " + script.src); }
        }, obj.timeout);
    }

    function logScript (obj, code, lang) {
        debug((code ?
            "Inline " + lang + ": " + code.replace("\n", " ").substr(0, 30) + "..." :
            "Inject " + obj.src), obj);
    }

    function separateScriptsFromHtml (htmlStr) {
        return split(htmlStr, splitScriptsRegex);
    }

    function split (str, regexp) {
        var match, prevIndex=0, tmp, result = [], i, l;

        if(support.splitWithCapturingParentheses) {
            tmp = str.split(regexp);
        } else {
            // Cross browser split technique from Steven Levithan
            // http://blog.stevenlevithan.com/archives/cross-browser-split
            tmp = [];
            while(match = regexp.exec(str)) {
                if(match.index > prevIndex) {
                    result.push(str.slice(prevIndex, match.index));
                }

                if(match.length > 1 && match.index < str.length) {
                    Array.prototype.push.apply(tmp, match.slice(1));
                }

                prevIndex = regexp.lastIndex;
            }

            if(prevIndex < str.length) {
                tmp.push(str.slice(prevIndex));
            }

        }

        for(i=0, l=tmp.length; i<l; i=i+1) {
            if(tmp[i]!=="") { result.push(tmp[i]); }
        }

        return result;
    }

    function stripNoScript (html) {
        return html.replace(/<noscript>[\s\S]*?<\/noscript>/ig, "");
    }

    function trim (str) {
        if(!str) { return str; }
        return str.replace(/^\s*|\s*$/gi, "");
    }

    function writeHtml (html, obj) {
        if( isScript(html) ) {
            var dummy = document.createElement("div");
            dummy.innerHTML = "dummy<div>" + html + "</div>"; // trick for IE
            var script = dummy.children[0].children[0];
            var lang = script.getAttribute("language") || "javascript";
            if(script.src) {
                obj.src = script.src;
                obj.charset = script.charset;
                obj.language = lang;
                obj.type = script.type;
                loadScript(obj);
            } else {
                var code = trim( script.text );
                if(code) {
                    logScript( obj, code, lang);
                    globalEval( code, lang);
                }
                flush(obj);
            }
        } else {
            var container = getCachedElById(obj.domId);
            if(!container) {
                throw new Error("crapLoader: Unable to inject html. Element with id '" + obj.domId + "' does not exist");
            }
            
            html = trim(html); // newline before <object> cause weird effects in IE
            if(html) {
                container.innerHTML += html;
            }
            checkWriteBuffer(obj);
        }
    }

    function writeReplacement (str) {
        inputBuffer.push(str);
        debug("write: " + str);
    }

    function openReplacement () {
        // document.open() just returns the document when called from a blocking script:
        // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-open
        return document;
    }

    function closeReplacement () {
        // document.close() does nothing when called from a blocking script:
        // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-close
    }

    publ = {
        hijack: function(options) {
            if(isHijacked) { return; }
            isHijacked = true;
            extend(globalOptions, options);
            if(globalOptions.parallel && !support.scriptOnloadTriggeredAccurately) {
                globalOptions.parallel = false;
                debug("Browsers onload is not reliable. Disabling parallel loading.");
            }

            document.write = document.writeln = writeReplacement;
            document.open = openReplacement;
            document.close = closeReplacement;
            document.getElementById = getElementByIdReplacement;
        },

        release: function() {
            if(!isHijacked) { return; }
            isHijacked = false;
            document.write = this.orgWrite;
            document.writeln = this.orgWriteLn;
            document.open = this.orgOpen;
            document.close = this.orgClose;
            document.getElementById = this.orgGetElementById;
            elementCache = {};
        },

        handle: function(options) {
            if(!isHijacked) {
                debug("Not in hijacked mode. Auto-hijacking.");
                this.hijack();
            }
            var defaultOptsCopy = extend({}, defaultOptions);
            var obj = extend(defaultOptsCopy, options);
            obj.depth = 0;

            if (!obj.domId) {
                obj.domId = "craploader_" + new Date().getTime();
                var span = document.createElement("span");
                span.id = obj.domId;
                document.body.appendChild(span);
            }

            if (options.func) {
                runFunc(obj);
                return;
            }

            if(globalOptions.parallel) {
                setTimeout(function() {
                    loadScript(obj);
                }, 1);
            } else {
                queue.push(obj);
                setTimeout(function() {
                    if(loading === 0) {
                        checkQueue();
                    }
                }, 1);
            }
        },

        loadScript: function(src, domId, options) {
            if (typeof domId !== "string") {
                options = domId;
                domId = undefined;
            }
            this.handle(extend({
                src:    src,
                domId:  domId
            }, options));
        },

        runFunc: function(func, domId, options) {
            if (typeof domId !== "string") {
                options = domId;
                domId = undefined;
            }
            this.handle( extend({
                domId:  domId,
                func:     func
            }, options) );
        },

        orgGetElementById   : document.getElementById,
        orgWrite            : document.write,
        orgWriteLn          : document.writeln,
        orgOpen             : document.open,
        orgClose            : document.close,
        _olt                : 1,
        _oltCallback        : function() {
            support.scriptOnloadTriggeredAccurately = (publ._olt===2);
        }
    };

    return publ;
}());
demo.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title> AD Loader </title>
  <style type="text/css">
  .banner1{margin:10px; border:1px solid #CCCCCC; width:728px; height:90px;}
  .banner2{margin:10px; border:1px solid #CCCCCC; width:300px; height:250px;}
  </style>
  <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
 </head>

 <body>
  <div class="banner1" id="ad_728x90"></div>
  <div class="banner2" id="ad_300x250"></div>
  <div class="banner2" id="ad_l2_300x250"></div>
   
  <?php
    function showAD($channel='', $step='', $async=''){
      include('ADLoader.class.php');
      $ad_config = include('ADConfig.php');
      ADLoader::setConfig($ad_config, 'ADLoader.js');
      return ADLoader::load($channel, $step, $async);
    }

    echo showAD('case_openx'); // 异步加载
    //echo showAD('case_url');   // url方式异步加载
    //echo showAD('case_sync_openx', 300, false); // 同步加载
  ?>

 </body>
</html>

adurl.php

<?php
$zoneid = isset($_GET['zoneid'])? intval($_GET['zoneid']) : 0;
if($zoneid){
?>
var zoneid = <?=$zoneid ?>;
var m3_u = (location.protocol=='https:'?'https://ads.nmg.com.hk/www/delivery/ajs.php':'http://ads.nmg.com.hk/www/delivery/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=" + zoneid);
document.write ('&cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
document.write ("&loc=" + escape(window.location));
if (document.referrer) document.write ("&referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
<? } ?>
源码下载地址:点击查看

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

php 广告加载类 的相关文章

  • JS小游戏-仙剑翻牌

    游戏介绍 这是一个翻牌配对游戏 xff0c 共十关 1 游戏随机从42张牌中抽取9张进行游戏 xff0c 每组为2张相同的牌 xff0c 共18张牌 2 连续翻到两张相同的为胜利 xff0c 当9组全部翻到则过关 如不是翻到连续两张相同的
  • memcached 常用命令及使用说明

    memcached 查看方法 格式 telnet ip port 例如 telnet localhost 11211 退出命令 xff1a quit 一 存储命令 存储命令格式 xff1a lt command name gt lt key
  • PHPMailer - PHP email transport class

    在服务器安装 sendmail sudo apt get install sendmail 启动 sendmail sudo etc init d sendmail start 修改 php ini mail function SMTP 6
  • PHP 遍历文件夹及文件类及处理类

    FindFile class php 用于遍历目录文件 lt php 遍历文件夹及文件类 Date 2013 03 21 Author fdipzone Ver 1 0 class FindFile public files 61 arra
  • sh autolog backup

    shell sh 每天备份log文件 bin bash 每天备份log文件 log path 61 34 home fdipzone logs 34 log目录 backup path 61 34 home fdipzone logs ba
  • Apache rewrite

    1 开启rewrite sudo a2enmod rewrite 2 停用rewrite sudo a2dismod rewrite 3 服务器环境变量 Apache提供给rewirte模块的环境变量大概分成5个类型 第一部分 HTTP h
  • RewriteCond和13个mod_rewrite应用举例Apache伪静态

    1 xff0e 给子域名加www标记 RewriteCond HTTP HOST a z 43 example com NC RewriteCond HTTP HOST www NC RewriteRule http www xample
  • 正向代理与反向代理的区别

    正向代理的概念 正向代理 也就是传说中的代理 他的工作原理就像一个跳板 简单的说 我是一个用户 我访问不了某网站 但是我能访问一个代理服务器 这个代理服务器呢 他能访问那个我不能访问的网站 于是我先连上代理服务器 告诉他我需要那个无法访问网
  • Apache 搭建虚拟主机

    Apache 搭建虚拟主机方法 DocumentRoot xff1a home fdipzone sites demo fdipzone com ServerName xff1a demo fdipzone com 1 进入apache虚拟
  • sh memcached 进程启动及监控

    memcached 进程启动及监控 1 memcached inc sh 设置路径 xff0c 端口等讯息 bin sh config include HOST 61 hostname SITE 61 34 mysite 34 PORT 6
  • 设置进程的显示名称

    有时候在LINUX下 xff0c fork子进程的时候 xff0c 像nginx里的一样 xff0c 想让子进程的名字可以自定义 参考网上文章之后 xff0c 可以通过修改argv 0 的值来改变子进程的名字 xff0c 但是要注意新标题的
  • 自动登入google play下载app report

    流程 1 登入google play 登入google play需要三步 https play google com apps publish https accounts google com ServiceLogin hl 61 en
  • sh cssupdate 优化

    bin bash 更新css文件内图片的版本 如background url 39 images test jpg 39 更新为 background url 39 images test jpg 20130330121210 39 css
  • php click captcha 验证码类

    需求 xff1a 现在常用的表单验证码大部分都是要用户输入为主 xff0c 但这样对手机用户会不方便 如果手机用户访问 xff0c 可以不用输入 xff0c 而是click某一位置便可确认验证码 xff0c 这样就会方便很多 原理 xff1
  • 快速排序算法

    快速排序 xff1a 代码 xff1a lt php 快速排序算法 1 在数组中找一个元素作为key 一般取数组第一个元素作为key 2 i 61 0 j 61 数组长度 1 3 j 当 arr j lt key arr i 与arr j
  • 利用Apache mod_expires 与 mod_headers 实现文件缓存及mod_deflate压缩输出

    1 使用mod deflate module 压缩输出 启动gzip 开启mod deflate sudo a2enmod deflate sudo etc init d apache2 restart 在httpd conf中添加 lt
  • HTML5 history API 介绍

    HTML5 history API介绍 history是个全局变量 xff0c 即window history 属性和方法如下 xff1a length xff1a 历史堆栈中的记录数 back xff1a 返回上一页 foward xff
  • 冒泡,二分法插入,快速排序算法

    1 冒泡排序算法 过程 xff1a 1 遍历整个数组 xff0c 每两两相邻的元素进行比较 xff0c 如 a i gt a i 43 1 则互换位置 xff0c 每次比较消除一个逆序 2 每一次循环后 xff0c 下次再需要循环的次数减少
  • PHP缩小png图片,保留透明色方法

    将图片缩成合适的尺寸 xff0c jpg图片缩小比较容易 xff0c png图片如果带了透明色 xff0c 按jpg方式来缩小 xff0c 会造成透明色丢失 保存透明色主要利用gd库的两个方法 xff1a imagecolorallocat
  • Ubuntu的常用快捷键

    Ubuntu Gnome的桌面技巧 xff1a 61 61 61 键盘类 61 61 61 1 先同时按住 Alt 43 Ctrl 键 xff0c 再按键盘上的左 右光标 键 可以切换工作区 2 web时按 键 等于 查找功能 桌面或者目录

随机推荐

  • 无人驾驶虚拟仿真(四)--通过ROS系统控制小车行走

    简介 xff1a 实现键盘控制虚拟仿真小车移动 xff0c w s a d 空格 xff0c 对应向前 向后 向左 向右 急停切换功能 xff0c q键退出 1 创建key control节点 进入工作空间源码目录 xff1a cd myr
  • error while loading shared libraries的解決方法

    error while loading shared libraries的解決方法 运行程式時 xff0c 如遇到像下列這種錯誤 xff1a tests error while loading shared libraries xxx so
  • imagemagick安装方法

    1 下载ImageMagick http www imagemagick org download 下载 ImageMagick 6 8 5 10 tar gz xff0c 下载完毕后开始进行安装 cd Downloads tar xzvf
  • ubuntu中安装apache ab命令进行简单压力测试

    1 安裝ab命令 sudo apt get install apache2 utils 2 ab命令参数说明 Usage ab options http s hostname port path Options are 总的请求数 n re
  • 如何查看当前Apache的连接数

    查看了连接数和当前的连接数 netstat ant grep ip 80 wc l netstat ant grep ip 80 grep EST wc l 查看IP访问次数 netstat nat grep 34 80 34 awk 39
  • php 获取页面中的指定内容类

    功能 xff1a 1 获取内容中的url xff0c email xff0c image 2 替换内容中的url xff0c email xff0c image url xff1a lt a href 61 34 url 34 gt xxx
  • memcached启动参数

    memcached启动参数 p 指定端口号 xff08 默认11211 xff09 U lt num gt UDP监听端口 默认 11211 0 时关闭 s lt file gt 用于监听的UNIX套接字路径 xff08 禁用网络支持 xf
  • mysql常用方法

    1 CONCAT str1 str2 mysql gt SELECT CONCAT 39 My 39 39 S 39 39 QL 39 gt 39 MySQL 39 mysql gt SELECT CONCAT 39 My 39 NULL
  • shell 监控网站是否异常的脚本

    shell 监控网站是否异常的脚本 xff0c 如有异常自动发电邮通知管理员 流程 xff1a 1 检查网站返回的http code 是否等于200 xff0c 如不是200视为异常 2 检查网站的访问时间 xff0c 超过MAXLOADT
  • 文件转base64输出

    Data URI scheme是在RFC2397中定义的 xff0c 目的是将一些小的数据 xff0c 直接嵌入到网页中 xff0c 从而不用再从外部文件载入 优点 xff1a 减少http连接数 缺点 xff1a 这种格式的文件不会被浏览
  • php 支持断点续传的文件下载类

    php 支持断点续传 xff0c 主要依靠HTTP协议中 header HTTP RANGE实现 HTTP断点续传原理 Http头 Range Content Range HTTP头中一般断点下载时才用到Range和Content Rang
  • 基于Linkit 7697的红绿灯控制系统

    1 硬件准备 LinkIt 7697 1 xff0c 继电器模块 1 xff0c 面包板 1 xff0c RGB LED灯 1 xff08 共阳极 xff0c 工作电流20mA xff0c 红灯压降2 2 2V xff0c 绿灯蓝灯压降3
  • shell 记录apache status并自动更新到数据库

    1 获取apache status monitor log sh bin bash 连接数 site connects 61 netstat ant grep ip 80 wc l 当前连接数 site cur connects 61 ne
  • php 缩略图生成类,支持imagemagick及gd库两种处理

    功能 1 按比例缩小 放大 2 填充背景色 3 按区域裁剪 4 添加水印 包括水印的位置 透明度等 使用imagemagick GD库实现 imagemagick地址 www imagemagick org 需要安装imagemagick
  • php5.3 中显示Deprecated: Assigning the return value of new by reference is deprecated in 的解决方法

    今天需要将某个网站般去另一台服务器 设置好运行 xff0c 显示一大堆Deprecated Deprecated Assigning the return value of new by reference is deprecated in
  • 使用apache mod_env模块保存php程序敏感信息

    Apache模块 mod env 说明 xff1a 允许Apache修改或清除传送到CGI脚本和SSI页面的环境变量 模块名 xff1a env module 源文件 xff1a mod env c 本模块用于控制传送给CGI脚本和SSI页
  • php 根据url自动生成缩略图

    原理 xff1a 设置apache rewrite xff0c 当图片不存在时 xff0c 调用php创建图片 例如 原图路径为 xff1a http localhost upload news 2013 07 21 1 jpg 缩略图路径
  • mailto 参数说明

    mailto 可以调用系统内置软件发送电子邮件 参数说明 mailto xff1a 收件人地址 xff0c 可多个 xff0c 用 分隔 cc xff1a 抄送人地址 xff0c 可多个 xff0c 用 分隔 bcc xff1a 密件抄送人
  • mysql 导入导出数据库

    mysql 导入导出数据库 1 导出数据 导出test 数据库 R 表示导出函数和存储过程 xff0c 加上使导出更完整 mysqldump u root p R test gt test sql 导出test数据库中user表 mysql
  • php 广告加载类

    php 广告加载类 xff0c 支持异步与同步加载 需要使用Jquery ADLoader class php lt php 广告加载管理类 Date 2013 08 04 Author fdipzone Ver 1 0 Func publ