Neredeyim ?

Muğla / Ortaca

Hızlı İletişim

buldurmert@gmail.com

Beni Takip Edebilirsin

Yazılarım

Siteyi Pc Girişlere Kapatma

Siteyi Pc Girişlere Kapatma

  • 3 dakika
  • 6 year ago
Blog Images

Bu yazımızda siteyi pc girişlerine kapatmayı görücez.Kimi zaman sitemizi pc , mobil , tablet gibi cihazların girişlerine kapatabiliriz veya siteye mobilden , tabletten giriş yapanları farklı bir yere yönlendirebilirsiniz.Veya giriş yapılan cihaza göre farklı çalışmalarda yapabilirsiniz.

Bunun için PHP tarafında hazırlanmış çok güzel eklenti var kullanımıda oldukça basit.

Öncelikle http://mobiledetect.net/ adresine gidiyoruz.Download sekmesinden Php dosyamızı indiriyoruz veyahut Composer üzerinden kurulumda yapabiliriz.

Bknz: 

composer require mobiledetect/mobiledetectlib

 

Composer üzerinden kurulum yaptığınızı veya dosyayı indirdiğinizi varsayarsak kodlama aşamasına geçebiliriz.

Kendi site üzerinden örnek kodları şu şekilde göstermektedir.

// Include and instantiate the class.
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
 
// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
 
}
 
// Any tablet device.
if( $detect->isTablet() ){
 
}
 
// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() ){
 
}
 
// Check for a specific platform with the help of the magic methods:
if( $detect->isiOS() ){
 
}
 
if( $detect->isAndroidOS() ){
 
}
 
// Alternative method is() for checking specific properties.
// WARNING: this method is in BETA, some keyword properties will change in the future.
$detect->is('Chrome')
$detect->is('iOS')
$detect->is('UC Browser')
// [...]
 
// Batch mode using setUserAgent():
$userAgents = array(
'Mozilla/5.0 (Linux; Android 4.0.4; Desire HD Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19',
'BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103',
// [...]
);
foreach($userAgents as $userAgent){
 
  $detect->setUserAgent($userAgent);
  $isMobile = $detect->isMobile();
  $isTablet = $detect->isTablet();
  // Use the force however you want.
 
}
 
// Get the version() of components.
// WARNING: this method is in BETA, some keyword properties will change in the future.
$detect->version('iPad'); // 4.3 (float)
$detect->version('iPhone') // 3.1 (float)
$detect->version('Android'); // 2.1 (float)
$detect->version('Opera Mini'); // 5.0 (float)
// [...]

Örnek olarak Siteyi sadece mobil cihazlara ve tabletlere açmak için ( yani PC ye kapatmak için ) aşagıdaki kodu kullanabilirsiniz.

require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
if(!$detect->isMobile() && !$detect->isTablet() ){ echo 'siteye giriş sadece pcden'; }

 

Yorumlar: