Basit Tarayıcı ve İşletim Sistemi Belirleme Sınıfı

<?php
class TarayiciTipi{
  var $bilgi; 
  function TarayiciTipi(){ 
		$this->bilgi = $_SERVER["HTTP_USER_AGENT"];
  }
  function tarayiciIsmiGetir(){
    $isim = "";
		if ($pos=strpos($this->bilgi,"Chrome")){
			$isim = trim(substr($this->bilgi,$pos,1000));
		}elseif ($pos=strpos($this->bilgi,"Firefox")){
			$isim = trim(substr($this->bilgi,$pos,1000));
		}elseif($pos=strpos($this->bilgi,"Safari")){
			$isim = trim(substr($this->bilgi,$pos,1000));
		}elseif($pos=strpos($this->bilgi,"Opera")){
			$isim = trim(substr($this->bilgi,$pos,1000));
		}elseif($pos=strpos($this->bilgi,"K-Meleon")){
			$isim = trim(substr($this->bilgi,$pos,1000));
		}elseif($pos=strpos($this->bilgi,"Firebird")){
			$isim = trim(substr($this->bilgi,$pos,1000));
		}elseif($pos=strpos($this->bilgi,"Netscape")){
			$isim = trim(substr($this->bilgi,$pos,1000));
		}elseif (preg_match("/Konqueror/",$this->bilgi)){
			$isim = "Konqueror";
		}elseif(preg_match("/Mozilla/",$this->bilgi)){
			$isim = "Mozilla/5.0";
		}else{ 
			$isim = "Diğer";
		}
		return ($isim);
  }
  function isletimSistemiIsmiGetir(){
    $isim = "";
		if (preg_match("/Windows/",$this->bilgi)){
			$isim = "Windows";
		}elseif (preg_match("/Linux/",$this->bilgi)){
			$isim = "Linux !";
		}elseif (preg_match("/Unix/",$this->bilgi)){
			$isim = "Unix";
		}else{ 
			$isim = "Diğer";
		}
		return $isim;
  }
}
$t = new TarayiciTipi();
echo "Tarayıcı Tipi : ".$t->tarayiciIsmiGetir()."<br>";
echo "İşletim Sistemi : ".$t->isletimSistemiIsmiGetir();
?>

Çıktısı

 

Basit Tarayıcı Bilgileri Tanıma Sınıfı

<?php
class tarayici{
	var $sonuc;
	function tarayici($bilgi){
		$sistem="Windows|iPad|iPhone|Macintosh|Android|BlackBerry";
		$tarayici="Firefox|Chrome"; 
		$tarayici_v="Safari|Mobile";
		$motor="Gecko|Trident|Webkit|Presto";
		$duzenli="/((Mozilla)\/[\d\.]+|(Opera)\/[\d\.]+)\s\(.*?((MSIE)\s([\d\.]+).*?(Windows)|({$sistem})).*?\s.*?({$motor})[\/\s]+[\d\.]+(\;\srv\:([\d\.]+)|.*?).*?(Version[\/\s]([\d\.]+)(.*?({$tarayici_v})|$)|(({$tarayici})[\/\s]+([\d\.]+))|$).*/i";
		$degistir='$7$8|$2$3|$9|${17}${15}$5$3|${18}${13}$6${11}';
		$bilgi_dizi=explode("|",preg_replace($duzenli, $degistir, $bilgi, PREG_PATTERN_ORDER));
		if(count($bilgi_dizi)>1){
			$sonuc['tarayici'] =$bilgi_dizi[3];
			if (preg_match("/^[\d]+\.[\d]+(?:\.[\d]{0,2}$)?/",$bilgi_dizi[4],$eslesme)){
				$sonuc['versiyon']=$eslesme[0];     
			}else{
				$sonuc['versiyon']=$bilgi_dizi[4];
			}
			$sonuc['sistem']=$bilgi_dizi[0];
			$sonuc['insa']=$bilgi_dizi[2];
			$sonuc['tip']=$bilgi_dizi[1];
		}else{
			return false;
		}
		switch(strtolower($sonuc['tarayici'])){
			case "msie":
			case "trident":
				$sonuc['tarayici']="Internet Explorer";
				break;
			case "": // IE 11 is a steamy turd (thanks Microsoft...)
				if (strtolower($sonuc['insa']) == "trident"){
					$sonuc['tarayici']="Internet Explorer";
				}
			break;
		}
		switch(strtolower($sonuc['sistem'])){
			case "android":
			case "blackberry":
				if ($sonuc['tarayici'] =="Safari" || $sonuc['tarayici'] == "Mobile" || $sonuc['tarayici'] == ""){
						$sonuc['tarayici']="{$sonuc['sistem']} mobile";
				}
				break;
			}
			$this->sonuc=$sonuc;
	}
}
$t=new tarayici($_SERVER['HTTP_USER_AGENT']);
print_r($t->sonuc);
?>

Çıktısı

Array
(
    [tarayici] => Chrome
    [versiyon] => 66.0
    [sistem] => Windows
    [insa] => WebKit
    [tip] => Mozilla
)

 

Eski Tarayıcılarda HTML5 Kullanabilmek

script tagı içerisinde bu kodları ekliyoruz

 (function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag(); a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/w+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x<style>article,aside,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}</style>"; c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="<xyz></xyz>";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode|| "undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup main mark meter nav output progress section summary time video",version:"3.6.2",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);if(g)return a.createDocumentFragment(); for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d<h;d++)c.createElement(e[d]);return c}};l.html5=e;q(f)})(this,document);

sayfa kodlarınızı ekleyerek test edebilirsiniz.

 <header>ulusanyazilim.com</header>
    <nav>Anasayfa</nav>
    <article>
        <section>
            HTML5
        </section>
    </article>
    <aside>
        Reklamlar
    </aside>
 <footer>Copyright</footer>

 

Eski Tarayıcılar için Placeholder Kullanımı

Öncelikle jquery kütüphanemizi script tagı ile çağırıyoruz.

http://code.jquery.com/jquery-1.10.2.min.js

script tagı içerisine kodlarımızı yazıyoruz.

;(function(window, document, $) {

    var isInputSupported = 'placeholder' in document.createElement('input');
    var isTextareaSupported = 'placeholder' in document.createElement('textarea');
    var prototype = $.fn;
    var valHooks = $.valHooks;
    var propHooks = $.propHooks;
    var hooks;
    var placeholder;

    if (isInputSupported && isTextareaSupported) {

        placeholder = prototype.placeholder = function() {
            return this;
        };

        placeholder.input = placeholder.textarea = true;

    } else {

        placeholder = prototype.placeholder = function() {
            var $this = this;
            $this
                .filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
                .not('.placeholder')
                .bind({
                    'focus.placeholder': clearPlaceholder,
                    'blur.placeholder': setPlaceholder
                })
                .data('placeholder-enabled', true)
                .trigger('blur.placeholder');
            return $this;
        };

        placeholder.input = isInputSupported;
        placeholder.textarea = isTextareaSupported;

        hooks = {
            'get': function(element) {
                var $element = $(element);

                var $passwordInput = $element.data('placeholder-password');
                if ($passwordInput) {
                    return $passwordInput[0].value;
                }

                return $element.data('placeholder-enabled') && $element.hasClass('placeholder') ? '' : element.value;
            },
            'set': function(element, value) {
                var $element = $(element);

                var $passwordInput = $element.data('placeholder-password');
                if ($passwordInput) {
                    return $passwordInput[0].value = value;
                }

                if (!$element.data('placeholder-enabled')) {
                    return element.value = value;
                }
                if (value == '') {
                    element.value = value;
                    // Issue #56: Setting the placeholder causes problems if the element continues to have focus.
                    if (element != document.activeElement) {
                        // We can't use `triggerHandler` here because of dummy text/password inputs :(
                        setPlaceholder.call(element);
                    }
                } else if ($element.hasClass('placeholder')) {
                    clearPlaceholder.call(element, true, value) || (element.value = value);
                } else {
                    element.value = value;
                }
                // `set` can not return `undefined`; see http://jsapi.info/jquery/1.7.1/val#L2363
                return $element;
            }
        };

        if (!isInputSupported) {
            valHooks.input = hooks;
            propHooks.value = hooks;
        }
        if (!isTextareaSupported) {
            valHooks.textarea = hooks;
            propHooks.value = hooks;
        }

        $(function() {
            // Look for forms
            $(document).delegate('form', 'submit.placeholder', function() {
                // Clear the placeholder values so they don't get submitted
                var $inputs = $('.placeholder', this).each(clearPlaceholder);
                setTimeout(function() {
                    $inputs.each(setPlaceholder);
                }, 10);
            });
        });

        // Clear placeholder values upon page reload
        $(window).bind('beforeunload.placeholder', function() {
            $('.placeholder').each(function() {
                this.value = '';
            });
        });

    }

    function args(elem) {
        // Return an object of element attributes
        var newAttrs = {};
        var rinlinejQuery = /^jQueryd+$/;
        $.each(elem.attributes, function(i, attr) {
            if (attr.specified && !rinlinejQuery.test(attr.name)) {
                newAttrs[attr.name] = attr.value;
            }
        });
        return newAttrs;
    }

    function clearPlaceholder(event, value) {
        var input = this;
        var $input = $(input);
        if (input.value == $input.attr('placeholder') && $input.hasClass('placeholder')) {
            if ($input.data('placeholder-password')) {
                $input = $input.hide().next().show().attr('id', $input.removeAttr('id').data('placeholder-id'));
                // If `clearPlaceholder` was called from `$.valHooks.input.set`
                if (event === true) {
                    return $input[0].value = value;
                }
                $input.focus();
            } else {
                input.value = '';
                $input.removeClass('placeholder');
                input == document.activeElement && input.select();
            }
        }
    }

    function setPlaceholder() {
        var $replacement;
        var input = this;
        var $input = $(input);
        var id = this.id;
        if (input.value == '') {
            if (input.type == 'password') {
                if (!$input.data('placeholder-textinput')) {
                    try {
                        $replacement = $input.clone().attr({ 'type': 'text' });
                    } catch(e) {
                        $replacement = $('<input>').attr($.extend(args(this), { 'type': 'text' }));
                    }
                    $replacement
                        .removeAttr('name')
                        .data({
                            'placeholder-password': $input,
                            'placeholder-id': id
                        })
                        .bind('focus.placeholder', clearPlaceholder);
                    $input
                        .data({
                            'placeholder-textinput': $replacement,
                            'placeholder-id': id
                        })
                        .before($replacement);
                }
                $input = $input.removeAttr('id').hide().prev().attr('id', id).show();
                // Note: `$input[0] != input` now!
            }
            $input.addClass('placeholder');
            $input[0].value = $input.attr('placeholder');
        } else {
            $input.removeClass('placeholder');
        }
    }

}(this, document, jQuery));

sayfa kodlarımızı ekliyoruz

<form>
    <input id="input" name="" type="text" placeholder="Birşeyler Arayın.."/>
</form>

en alta script tagı içerisine kodlarımızı ekliyoruz.

 $(function() {
        $('input, textarea').placeholder();
        var html;
        if ($.fn.placeholder.input && $.fn.placeholder.textarea) {
         html = '<strong>Your current browser natively supports <code>placeholder</code> for <code>input</code> and <code>textarea</code> elements.</strong> The plugin won’t run in this case, since it’s not needed. If you want to test the plugin, use an older browser ;)';
        } else if ($.fn.placeholder.input) {
         html = '<strong>Your current browser natively supports <code>placeholder</code> for <code>input</code> elements, but not for <code>textarea</code> elements.</strong> The plugin will only do its thang on the <code>textarea</code>s.';
        }
        if (html) {
         $('<p class="note">' + html + '</p>').insertAfter('form');
        }
     });