CUCEKO.NET ▌ 83/1 PK FARM SERVER ▌ FULL İTEM BAŞLANGIÇ ▌ OFFICIAL: 29.03.2024 / SAAT 22:000
Cuceko
Cuceko

PHP | Gelişmiş Lisanslama Mekanizması - CACHE Entegreli

  •         

            

            

            

            

  • HyperFilter | DoS Protection | DDoS Protection | DoS Mitigation | DDoS Mitigation | AntiDoS | AntiDDoS | Proxy Shielding
S Çevrimdışı

saintx

Kayıtlı Üye
12 Mart 2012
250
0
18
27
Merhaba arkadaşlar,



Sistemi tamamiyle değiştirdim ve sınıfsal bir yapıya kavuşturdum.Sizlerin yorumları doğrultusunda cache sistemini entegre ettim.

Öncelikle nasıl kuracağınızı adım adım anlatacağım.



1-) alttaki kodu lisans.php diyerek ana dizine kaydediyoruz.

İçerik Açılmıştır Teşekkürler :)
Kod:
<?php

	

	class checklicense

	{

		

		protected $cl_license_server;

		protected $cl_ip_address;

		protected $cl_product_key;

		protected $cl_license_array;

		

		/* önbellekleme değişkenleri */

		

		protected $cl_cache_time;

		protected $cl_cache_file;

		

		public function __construct($license_server, $cache_time)

		{

			$this->cl_ip_address		= $_SERVER['HTTP_HOST'];

			$this->cl_product_key		= null;

			$this->cl_license_server	= $license_server;

			$this->cl_cache_time		= $cache_time;

			$this->cl_cache_file		= 'cache/'.md5($this->cl_license_server.$this->cl_ip_address).'.cache';

			/* Çalıştırmalar */

			$this->_check_ip_address();

			$this->_create_product_key();

			if( $this->_is_available_cache() != true )

			{

				$this->_write_cache($this->cl_cache_file, $this->_get_license_file());

				$this->_check_license($this->_read_cache($this->cl_cache_file));

			}

			else

			{

				$this->_check_license($this->_read_cache($this->cl_cache_file));

			}

		}

		

		/* IP Kontrolleri */

		

		protected function _check_ip_address()

		{

			if( ! is_numeric(substr($this->cl_ip_address, 0, 3)) )

			{

				if( substr($this->cl_ip_address, 0, 4) == 'www.' )

				{

					$this->cl_ip_address = substr($this->cl_ip_address, 4);

				}

			}

		}

		

		/* Ürün anahtarı oluşturma ve kontroller */

		

		protected function _create_product_key()

		{

			$this->cl_product_key = wordwrap(strtoupper(md5(sha1(sha1($this->cl_product_key)))), 4, '-', true);

		}

		

		protected function _check_license(array $data)

		{

			if( ! in_array($this->cl_product_key, $data) )

			{

				die($_SERVER['HTTP_HOST'].' isimli sunucunuzun lisansı bulunmamaktadır.');

				exit;

			}

		}

		

		/* Uzak sunucudan dosya okuma işlemleri */

		

		protected function _get_license_file()

		{

			if( function_exists('file') )

			{

				$file = file($this->cl_license_server, FILE_IGNORE_NEW_LINES);

				$data = array();

				foreach($file as $key => $value)

				{

					$data[$key] = rtrim($value, '\r\n');

				}

				return $data;

			}

		}

		

		/* Önbellekleme Fonksiyonları */

		

		protected function _is_available_cache()

		{

			$this->cl_cache_file = 'cache/'.md5($this->cl_license_server.$this->cl_ip_address).'.cache';

			if( ! file_exists($this->cl_cache_file) ) return false;

			$this->cl_cache_time = $this->cl_cache_time * 60;

			if( time() - filemtime($this->cl_cache_file) > $this->cl_cache_time )

			{

				unlink($this->cl_cache_file);

				return false;

			}

			return true;

		}

		

		protected function _write_cache($path, $data)

		{

			$handler = fopen($path, 'a');

			fwrite($handler, serialize($data));

			fclose($handler);

		}

		

		protected function _read_cache($path)

		{

			$data = unserialize(file_get_contents($path));

			return $data;

		}

	}

	

?>
2-) scriptinizin kilit dosyalarından bir tanesine şu kodları en üst kısma ekliyoruz. ;

İçerik Açılmıştır Teşekkürler :)
PHP:
include('lisans.php');

new checklicense('http://127.0.0.1:81/lisans.txt', 10); // 1. parametre lisans dosyası 2. parametre kaç dakika cache kalacak.
3-) lisanslamak istediğiniz sunucu için bir adet key oluşturmanız gerekir bu key'i ise şu kodlar ile oluşturacağız.

İçerik Açılmıştır Teşekkürler :)
Kod:
<?php

    

    $lisans_adresi = 'www.saintx.net';

    $olustur = wordwrap(strtoupper(md5(sha1(sha1($lisans_adresi)))), 4, '-', true);

    echo $lisans_adresi.'\'i için oluşturulan ürün anahtarı ;';

    echo '

';

    echo $olustur;

    

?>
4-) yemeğimiz hazır :) iyi forumlar ben .ogün! ~~ saintx
 
X Çevrimdışı

XirTR

Kayıtlı Üye
20 Mayıs 2012
520
2
18
29
Bi sistem de ben paylaşayım bundan biraz farklı benim paylaşacağım biraz daha kolay olucak yani gapışceesek gapılaım :)
 
E Çevrimdışı

exselansTR

Kayıtlı Üye
4 Nisan 2012
127
0
16
32
Deneyek :)

[MENTION=74]ognkrks[/MENTION] sanki aşılabilir gibi, şu cache olayından bir açık düşündüm hani.