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

PHP
63 lines
<?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']);
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

PHP
1 lines
2
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

gecmis.txt

Text
1 lines
212.74.253.133,1527946050|173.247.117.141,1527946093
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Düzenli İfade İle Veri Girişi Doğrulama Kontrol Sınıfı

PHP
37 lines
<?php
class duzenliIfadeKontrol {
public static function epostaKontrol($metin){
return self::kontrol($metin,"/^[^@]*@[^@]*\.[^@]*$/");
}
public static function ipKontrol($metin){
return self::kontrol($metin,"/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/");
}
public static function hexRenkKontrol($metin){
return self::kontrol($metin,"/^#[a-fA-F0-9]{6}$/");
}
public static function hexNoKontrol($metin){
return self::kontrol($metin,"/^[a-fA-F0-9]{6}$/");
}
public static function rakamKontrol($metin){
return self::kontrol($metin,"/^[-+]?\b[0-9]+(\.[0-9]+)?$/");
}
public static function sayiKontrol($metin){
return self::kontrol($metin,"/^[-+]?\b[0-9]*\.?[0-9]+$/");
}
public static function kullaniciKontrol($metin){
return self::kontrol($metin,"/^[a-z\d_]{4,28}$/i");
}
private static function kontrol($metin,$kural){
if (preg_match($kural,$metin))
return true;
return false;
}
}
echo "E-POSTA: ".duzenliIfadeKontrol::epostaKontrol("jordigirones@gmail.com")."<br>";
echo "IP: ".duzenliIfadeKontrol::ipKontrol("192.168.12.31")."<br>";
echo "HEX RENK: ".duzenliIfadeKontrol::hexRenkKontrol("#336AA9")."<br>";
echo "HEX NO: ".duzenliIfadeKontrol::hexNoKontrol("336AA9")."<br>";
echo "RAKAM: ".duzenliIfadeKontrol::rakamKontrol("12345")."<br>";
echo "SAYI: ".duzenliIfadeKontrol::sayiKontrol("12345.6789")."<br>";
echo "KULLANICI: ".duzenliIfadeKontrol::kullaniciKontrol("jgirones");
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
7 lines
E-POSTA: 1
IP: 1
HEX RENK: 1
HEX NO: 1
RAKAM: 1
SAYI: 1
KULLANICI: 1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX