İki Tarih Arasındaki Farkı Bulmak

<?php
class ZamanFarkiHesapla{
	var $damga1;
	var $damga2;
	function yilGetir($veri){
	   $sonuc=getdate($veri);
	   return ($sonuc['year']);
	}
	function gunGetir($damga){
	   $sonuc=getdate($damga);
	   return (($sonuc['yday'])+1);
	}
	function yilGun($year){
		$sonuc=$this->gunGetir(strtotime("$year-12-31"));
		return $sonuc;
	}
	function gecenYilGun($damga){
		$year=$this->yilGetir($damga);
		$sonuc=$this->gunGetir(strtotime("$year-12-31"));
		return $sonuc;
	}
	function sonYilGunu($damga){
		$gecen_yil_gun=$this->gecenYilGun($damga);
		$gun_getir=$this->gunGetir($damga);
		return ($gecen_yil_gun-$gun_getir);

	}
	function farkGetir($d1,$d2){
		$ortala=0;
		$this->damga1=strtotime($d1);
		$this->damga2=strtotime($d2);
		$yil1=$this->yilGetir($this->damga1);
		$yil2=$this->yilGetir($this->damga2);
		$fark=$yil2 - $yil1;
		switch ($fark)		{
			case '0':
				$gun1=$this->gunGetir($this->damga1);
				$gun2=$this->gunGetir($this->damga2);
				$sonuc=$gun2-$gun1;
			break;
			case '1':
				$gun1=$this->sonYilGunu($this->damga1);
				$gun2=$this->gunGetir($this->damga2);
				$sonuc=$gun1+$gun2;
			break;
			case $fark>=2:
				$gun1=$this->sonYilGunu($this->damga1);
				$gun2=$this->gunGetir($this->damga2);
				for( $i=(( $this->yilGetir($this->damga1) )+1);$i<( $this->yilGetir($this->damga2) );$i++ )
					$ortala+=$this->yilGun($i);
				$sonuc=$gun1+$gun2+$ortala;
			break;
		}
		return $sonuc;				
	}
}	
$dateDiff= new ZamanFarkiHesapla();
echo $dateDiff->farkGetir("1914-07-28","2018-06-05");//1.Dünya Savaşı
?>

Çıktısı

37933

 

Uzak Sunucuya Erişim Kontrolü

<?php
class durum{
	function sunucu($adres){
			 if(strstr($adres,"/")){$adres = substr($adres, 0, strpos($adres, "/"));}
			 return $adres;
	}
	function durum($adres="",$port=80,$zamanasimi=3) {
		if($adres=="") $adres = $_SERVER['REMOTE_ADDR'];
		$churl = fsockopen($adres, $port, $errno, $errstr, $zamanasimi); 
		if (!$churl){
			echo 'Sunucu Çevrimdışı';
		} else{
			echo 'Sunucu Çevrimiçi';
		}
	}
	function portkontrol($adres,$zamanasimi,$port) {
		if($adres=="") $adres = $_SERVER['REMOTE_ADDR'];
		$churl = @fsockopen($adres, $port, $errno, $errstr, $zamanasimi); 
		if (!$churl){
			echo "Port $port çalışmıyor";
		}else{
			echo "Port $port çalışıyor";
		}
	}
}
$durum = new durum("216.58.212.46");
echo '<br>';
$durum->portkontrol("216.58.212.46",1,80);//google ip
?>

Çıktısı

Sunucu Çevrimiçi
Port 80 çalışıyor

 

Yerelleştirme Sınıfı ile Dosyadan Farklı Dil Çevirilerini Almak

index.php

<?php
class Yerellestirme{
	var $ulke;
	var $dil;
	function Yerellestirme($dil,$ulke){
		$this->ulke=$ulke;
		$this->dil=$dil;
	}
	function Cevir($metin){
		include ($this->dil)."_".($this->ulke).".inc";
		return $$metin;
	}
}
$En=new Yerellestirme("en","US");
print($En->Cevir("helloworld"));
echo "<br>";
$Tr=new Yerellestirme("tr","TR");
print($Tr->Cevir("helloworld"));
?>

en_US.inc

<?php
$helloworld="Hello World ";
?>

tr_TR.inc

<?php
$helloworld="Merhaba Dünya ";
?>

Çıktısı

Hello World 
Merhaba Dünya

 

Yığın Sınıfı ile Dizi İşlemleri

<?php
class Yigin {
	var $dizi = array();
	function push($eleman) {
		array_push($this->dizi, $eleman);
	}
	function pop() {
		$eleman = $this->top();
		array_pop($this->dizi);
		return $eleman;
	}
	function top() {
		$say = count($this->dizi);
		if ($say == 0) {
			return null;
		}
		return $this->dizi[count($this->dizi)-1];
	}
	function uzunluk() {
		return count($this->dizi);
	}
}
$s=new Yigin;
$s->push(["test1","test2"]);
$s->push(["test3"]);
$s->push(["test4"]);
print_r($s->dizi);
print_r($s->pop());
print_r($s->dizi);
print_r($s->top());
print_r($s->uzunluk());
?>

Çıktısı

Array
(
    [0] => Array
        (
            [0] => test1
            [1] => test2
        )

    [1] => Array
        (
            [0] => test3
        )

    [2] => Array
        (
            [0] => test4
        )

)
Array
(
    [0] => test4
)
Array
(
    [0] => Array
        (
            [0] => test1
            [1] => test2
        )

    [1] => Array
        (
            [0] => test3
        )

)
Array
(
    [0] => test3
)
2

 

Rastgele Proxy Listesi Almak

<?php
set_time_limit(0);
class Vekil {
	var $sayfa;
	var $liste;
  function cagir() {
    $this->sayfa = file_get_contents("http://www.proxy4free.com/list/webproxy1.html");
	}
  function ayristir() {
    preg_match("/<table class=\"table table-striped proxy-list\">(.*?)<\/table>/si", $this->sayfa,$cikti);
		preg_match_all("/<tr>(.*?)<\/tr>/si",$cikti[1],$sonuc);
		foreach($sonuc[1] as $value){			
			preg_match("/<a class=\"info\" href=\"http:\/\/iplocation.com\/(.*?)\"><\/a>/si",$value,$ip);
			if(isset($ip[1])){
				if(strstr($ip[1],"?ip=")){
					$this->liste[]=str_replace("?ip=","",$ip[1]);
				}
			}
		}
  }
  function rastgele() {
    $say = count($this->liste)-1;
    $rastgele = rand(0, $say);
    return $this->liste[$rastgele];
  }
}
$proxy = new Vekil();
$proxy->cagir();
$proxy->ayristir();
echo $proxy->rastgele();
?>

Çıktısı

185.14.31.78

 

Basit XML Oluşturma Sınıfı

<?php
Class XML{
	var $icerik="";
	var $anaEtiket="";
	var $altEtiket="";
	var $CRLF="\r\n";
	var $son="";
	Function XML($Version="1.0",$Encoding="utf-8"){
		$this->icerik.="<?xml version=\"{$Version}\" encoding=\"{$Encoding}\"?>{$this->CRLF}";
	}
	Function etiketOlustur($etiketIsmi="root",$ozellik=""){
		$etiketIsmi=$this->filtre($etiketIsmi);
		$this->anaEtiket=$etiketIsmi;
		$ozellik=$this->ozellikAyir($ozellik);
		return $this->icerik.="<{$etiketIsmi}{$ozellik}>{$this->CRLF}";
	}
	Function etiketEkle($etiketIsmi,$ozellik,$veri="",$CDATA=true){
		$etiketIsmi=$this->filtre($etiketIsmi);
		if(empty($veri)){
			if(!empty($this->altEtiket)){
				$this->icerik.="</{$this->altEtiket}>{$this->CRLF}";
			}
			$this->altEtiket=$etiketIsmi;
			$ozellik=$this->ozellikAyir($ozellik);
			return $this->icerik.="<{$etiketIsmi}{$ozellik}>{$this->CRLF}";
		}else{
			$ozellik=$this->ozellikAyir($ozellik);
			return $this->icerik.=$CDATA?"<{$etiketIsmi}{$ozellik}>{$this->CRLF}<![CDATA[{$veri}]]>{$this->CRLF}</{$etiketIsmi}>{$this->CRLF}":"<{$etiketIsmi}{$ozellik}>{$veri}</{$etiketIsmi}>{$this->CRLF}";
		}
	}
	Function son(){
		if($this->son){
			return $this->icerik;
		}else{
			$this->son=true;
			return $this->icerik=$this->altEtiket==""?$this->icerik."</{$this->anaEtiket}>":$this->icerik."</{$this->altEtiket}>{$this->CRLF}</{$this->anaEtiket}>";
		}
	}
	Function goster(){
		ob_start();
		header("Content-type: text/xml");
		echo $this->son();
		ob_end_flush();
	}
	Function kaydet($dosya){
		if(!$Handle=fopen($dosya,'wb+')){
			$this->hata("Dosya Yazılamıyor");
		}
		flock($Handle,LOCK_EX);
		fwrite($Handle,$this->son());
		return fclose($Handle);
	}
	Function hata($hataMetni='',$hataNo='',$Stop=true){
		exit($hataMetni);
	}
	Function ozellikAyir($veri){
		$ozellik='';
		if(is_array($veri)){
			foreach($veri as $anahtar=>$deger){
				$deger=$this->filtre($deger);
				$ozellik.=" $anahtar=\"$deger\"";
			}
		}
		return $ozellik;
	}
	Function filtre($veri){
		$veri=trim($veri);
		$ara=array("<",">","\"");
		$degistir=array("","","'");
		return str_replace($ara,$degistir,$veri);
	}
}
$n=new XML($Version="1.0",$Encoding="utf-8");
$n->etiketOlustur($etiketIsmi="site",'');

$n->etiketEkle("kategori",'',$veri="Bu bir test yazısıdır",$CDATA=true);
$n->goster();
$n->kaydet($dosya="data.xml");
$n->hata();
$n->son();
?>

Çıktısı

<site>
<kategori>
<![CDATA[ Bu bir test yazısıdır ]]>
</kategori>
</site>

 

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
)

 

Mors Sınıfı ile Gelişmiş Mors Alfabesine ve Yazıya Çevirme

<?php
class Mors{
	private static $mors=array(
		"a"=>".-","b"=>"-...","c"=>"-.-.","d"=>"-..","e"=>".","f"=>"..-.","g"=>"--.",
		"h"=>"....","i"=>"..","j"=>".---","k"=>"-.-","l"=>".-..","m"=>"--","n"=>"-.",
		"o"=>"---","p"=>".--.","q"=>"--.-","r"=>".-.","s"=>"...","t"=>"-","u"=>"..-",
		"v"=>"...-","w"=>".--","x"=>"-..-","y"=>"-.--","z"=>"--..","1"=>".----",
		"2"=>"..---","3"=>"...--","4"=>"....-","5"=>".....","6"=>"-....","7"=>"--...",
		"8"=>"---..","9"=>"----.","0"=>"-----"," "=>"   ","."=>".-.-.-",","=>"--..--",
		"?"=>"..--..","!"=>"..--.",":"=>"---...","'"=>".----.","\""=>".-..-.",
		"="=>"-...-","EOM"=>".-.-."
	);
	private static $yazis=array();
	static function kelime($kelime){
		mb_strtolower($kelime);
		$kelime = str_replace("&", "&", $kelime);
		$kelime = preg_replace("/&([a-z]+);/", "", $kelime); 
		$kelime = str_replace(
		array("$","^","*",";","%","~","@","#","[","]","<",">","\\","/","+"), 
		"", $kelime);
		$kelime = str_replace(
		array('_',"&",'ç','ş','ı','í','ì','î','ï','ú','ü','ù','û','á','ä','â','à','â','ó','ö','ò','ô','ô','ğ'), 
		array("-","ve",'c','s','i','i','y','y','i','u','u','u','u','a','a','a','a','a','o','o','o','o','o','g'), $kelime);  
		return strtolower($kelime);
	}
	static function MorsaCevir($kelime) {
		$kelime=Mors::kelime($kelime);
		$yazdir = "";
		for ($i = 0; $i < strlen($kelime); $i++) {
			$yazi = substr($kelime,$i,1);
			// ignore unknown harfacters
			if (self::$mors[$yazi] == "") continue;
			$yazdir .= (self::$mors[$yazi]." ");
		}
		return trim($yazdir);
	}
	static function YaziyaCevir($kelime) {
		$kelime = strtolower($kelime);
		reset(self::$mors);
		while (list($yazi,$kod) = each(self::$mors)) {
			self::$yazis[$kod] = $yazi;
		}
		$yazdir = "";
		$kelimeler = array();
		$harfler = array();
		$kelimeler = preg_split("/".self::$mors[" "]."/", $kelime, -1, PREG_SPLIT_NO_EMPTY);
		foreach ($kelimeler as $kelime) {
			$harfler = array_merge($harfler, preg_split("/ /", $kelime, -1, PREG_SPLIT_NO_EMPTY));
			$harfler[] = '';
		}
		$harfler[count($harfler)-1] = self::$mors["EOM"];
		foreach ($harfler as $harf) {
			// ignore unknown harfacters
			if ($harf == "") {
				$yazdir .= " ";
			}
			if ($harf == self::$mors["EOM"]) {
				break;
			}
			if (@self::$yazis[$harf] == "") {
				continue;
			}
			$yazdir .= self::$yazis[$harf];
		}
		return trim($yazdir);
	}
}
echo $mors=Mors::MorsaCevir('Bu bir deneme yazısıdır');
echo '<br>';
echo Mors::YaziyaCevir($mors);
?>

Çıktısı

-... ..- -... .. .-. -.. . -. . -- . -.-- .- --.. .. ... .. -.. .. .-.
bu bir deneme yazisidir

 

Çevrimiçi Kullanıcıları IP Adresine Göre Almak

<?php
	class kimlerCevrimici{
		public $yol;
		var $dakika = 5; 
		var $dosya = 'gecmis.txt';
		var $gecmis = array();
		var $sayac = 0;	
		function __construct(){
			if(!file_exists($this->dosya)){
				file_put_contents($this->dosya,"");
			}
		}
		function kullaniciAl($ip){
			$dosya = fopen($this->yol . $this->dosya, 'r');		
			$gecmis = '';			
			while (!feof($dosya)) {
				$gecmis .= fread($dosya, 8192);
			}			
			fclose($dosya);
			$this->gecmis = explode('|', $gecmis);
			$p = strpos($gecmis, $ip);
			if ($p === false){
				$this->gecmis[sizeof($this->gecmis)] = $ip.','.time();
			}
		}
		function guncelle(){
			if ($dosya = fopen($this->yol . $this->dosya, 'w+')){
				$gecmisMetin = '';
				foreach($this->gecmis as $i => $v){
					if (strlen(trim($v)) > 0){
						$kullanici = explode(',', $v);
						$gecmisMetin .= $kullanici[0].','.$kullanici[1].'|';
					}
				}
				$gecmisMetin = substr($gecmisMetin, 0, strlen($gecmisMetin) - 1);
				if (fwrite($dosya, $gecmisMetin)){
					return true;
				}else{
					return false;
				}
			}else{
				return false;
			}
		}
		function kac($ip){
			$this->kullaniciAl($ip);
			$this->sayac = 0;
			foreach($this->gecmis as $i => $v){
				$kullanici = explode(',', $v);
				
				if ($kullanici[1] > (time() - $this->dakika * 60) || $kullanici[0] == $ip){
					$this->sayac++;
				}else{
					$gecmis[$i] = '';
				}
			}
			$this->guncelle();
			return $this->sayac;
		}
	}
	$u = new kimlerCevrimici;
	echo $u->kac($_SERVER['REMOTE_ADDR']);
?>

Çıktısı

2

gecmis.txt

212.74.253.133,1527946050|173.247.117.141,1527946093

 

Genişletilmiş Tarih Metni Sınıfı

<?php
Class genisTarih {
	var $data;
	var $bol;
	var $sonuc;
	var $ay;
	function gunu($gun){
		switch ($gun){
		case 1: $this->sonuc = "birinci"; break;
		case 2: $this->sonuc = "ikinci"; break;
		case 3: $this->sonuc = "üçüncü"; break;
		case 4: $this->sonuc = "dördüncü"; break;
		case 5: $this->sonuc = "beşinci"; break;
		case 6: $this->sonuc = "altıncı"; break;
		case 7: $this->sonuc = "yedinci"; break;
		case 8: $this->sonuc = "sekizinci"; break;
		case 9: $this->sonuc = "dokuzuncu"; break;
		case 10: $this->sonuc = "on"; break;
		case 20: $this->sonuc = "yirmi"; break;
		case 30: $this->sonuc = "otuz"; break;
		}
		return $this->sonuc;
	}	
	function gun($gun){
		if(($gun - 30) > 0){
		$this->sonuc = $this->gun(30)." ".$this->gun($gun - 30);	
		} elseif(($gun - 20) > 0){
		$this->sonuc = $this->gun(20)." ".$this->gun($gun - 20);
		} elseif(($gun - 10) > 0){
		$this->sonuc = $this->gun(10)." ".$this->gun($gun - 10);
		} else {
		$this->sonuc = $this->gun($gun);
		}
		return $this->sonuc;
	}
	function ay($ay){
	$this->ay = array('Ocak','Şubat','Mart','Nisan','Mayıs','Haziran','Temmuz','Ağustos','Eylül','Ekim','Kasım','Aralık');
	$this->sonuc = $this->ay[floor($ay)-1];
	return $this->sonuc;
	}
	function genisTarih($data){
	$this->bol = explode("/", $data);
	$gun = $this->gunu($this->bol[0]);
	$this->sonuc = "Bugun ".$this->bol[2]." yılının ".$this->ay($this->bol[1])." ayının ".$gun." günündeyiz.";
	echo ucfirst($this->sonuc);
	}
}
new genisTarih(date("d/m/Y"));
?>

Çıktısı

Bugun 2018 yılının Haziran ayının ikinci günündeyiz.