$_Get $_Post $_Session $_Cookie $_Files $_Server Girdilerini Temizlemek

<?php
session_start();
class girdi{
	function girdi(){
		if(get_magic_quotes_gpc()){
			if(isset($_GET)		&& !isset($this->get))		$this->get		=	$this->temiz($_GET,false);
			if(isset($_POST)	&& !isset($this->post))		$this->post		=	$this->temiz($_POST,false);
			if(isset($_COOKIE)	&& !isset($this->cookie))	$this->cookie	=	$this->temiz($_COOKIE,false);
			if(isset($_SESSION)	&& !isset($this->session))	$this->session	=	$this->temiz($_SESSION,false);
			if(isset($_FILES)	&& !isset($this->files))	$this->files	=	$this->temiz($_FILES,false);
			if(isset($_SERVER)	&& !isset($this->server))	$this->server	=	$this->temiz($_SERVER,false);
		}else{
			if(isset($_GET)		&& !isset($this->get))		$this->get		=	$this->temiz($_GET,true);
			if(isset($_POST)	&& !isset($this->post))		$this->post		=	$this->temiz($_POST,true);
			if(isset($_COOKIE)	&& !isset($this->cookie))	$this->cookie	=	$this->temiz($_COOKIE,true);
			if(isset($_SESSION)	&& !isset($this->session))	$this->session	=	$this->temiz($_SESSION,true);
			if(isset($_FILES)	&& !isset($this->files))	$this->files	=	$this->temiz($_FILES,true);
			if(isset($_SERVER)	&& !isset($this->server))	$this->server	=	$this->temiz($_SERVER,false);
		}
		if(!isset($this->url)) $this->url	=	substr(@$this->server['PATH_INFO'],-1)!='/'?	basename($this->server['SCRIPT_NAME']).@$this->server['PATH_INFO'].'/':basename($this->server['SCRIPT_NAME']).@$this->server['PATH_INFO'];
		
		if(!isset($this->uri))	$this->uri=explode('/',substr(@$this->server['PATH_INFO'],-1)!='/'	?	basename($this->server['SCRIPT_NAME']).@$this->server['PATH_INFO']:basename($this->server['SCRIPT_NAME']).substr(@$this->server['PATH_INFO'],0,-1));
	}
	function temiz($veri, $temiz = true){
		$cikti=null;
		if(is_array($veri)){
			foreach($veri as $girdi=>$deger){
				$cikti[$girdi] = $this->temiz($deger,$temiz);
			}
			return $cikti;
		}elseif($temiz){
			return addslashes($veri);
		}else{
			return $veri;
		}
	}
}
$girdi = new girdi();
print_r($girdi->get);
print_r($girdi->post);
print_r($girdi->session);
print_r($girdi->cookie);
print_r($girdi->files);
print_r($girdi->server);
?>

Çıktısı

Array
(
    [PHPSESSID] => 908egm9dcnr2jqfgog4
)
Array
(
    [TMP] => C:/binaries/tmp
    [HTTP_HOST] => 127.0.0.1
    [HTTP_CONNECTION] => keep-alive
    [HTTP_CACHE_CONTROL] => max-age=0
    [HTTP_UPGRADE_INSECURE_REQUESTS] => 1
    [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
    [HTTP_ACCEPT_ENCODING] => gzip, deflate, br
    [HTTP_ACCEPT_LANGUAGE] => tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7
    [HTTP_COOKIE] => PHPSESSID=908egm9dcnr2jqfgog4
    [PATH] => C:\php_runningversion; C:\Windows\system32;C:\Apache\bin;C:\PHP
    [SystemRoot] => C:\Windows
    [COMSPEC] => C:\Windows\system32\cmd.exe
    [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
    [WINDIR] => C:\Windows
    [SERVER_SIGNATURE] => 
    [SERVER_SOFTWARE] => Apache/2.4.7 (Win32) PHP/5.4.24
    [SERVER_NAME] => 127.0.0.1
    [SERVER_ADDR] => 127.0.0.1
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 127.0.0.1
    [DOCUMENT_ROOT] => C:/data/localweb
    [REQUEST_SCHEME] => http
    [CONTEXT_PREFIX] => 
    [CONTEXT_DOCUMENT_ROOT] => C:/data/localweb
    [SERVER_ADMIN] => admin@127.0.0.1
    [SCRIPT_FILENAME] => C:/data/localweb/index.php
    [REMOTE_PORT] => 535583
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => 
    [REQUEST_URI] => /
    [SCRIPT_NAME] => /index.php
    [PHP_SELF] => /index.php
    [REQUEST_TIME_FLOAT] => 152836397.365
    [REQUEST_TIME] => 1528368397
)

 

Post, Get, Request ve Cookie Değerleri Temizleme Sınıfı

<?php
class temizle {
	function temizle() {
		$this->temizleCookie();
		$this->temizleGet();
		$this->temizleRequest();
		$this->temizlePost();
	}
	function temizlePost() {
		foreach($_POST as $anahtar=>$deger) {
			$_POST[$anahtar] = addslashes($deger);
		}
	}
	function temizleGet() {
		foreach($_GET as $anahtar=>$deger) {
			$_GET[$anahtar] = addslashes($deger);
		}
	}
	function temizleRequest() {
		foreach($_REQUEST as $anahtar=>$deger) {
			$_REQUEST[$anahtar] = addslashes($deger);
		}
	}
	function temizleCookie() {
		foreach($_COOKIE as $anahtar=>$deger) {
			$_COOKIE[$anahtar] = addslashes($deger);
		}
	}
}
$_POST = array('isim'=>"Ahmet'in", 'deger'=>"Kalem'i");
$_GET = array('id'=>"nerde'");
$_REQUEST = array('deger'=>'test"');
$_COOKIE = array('sifre'=>"'osman'in_sifresi");
echo '<fieldset><legend>Eski Hali</legend>';
echo 'POST: ';
print_r($_POST);
echo '<br>GET: ';
print_r($_GET);
echo '<br>REQUEST: ';
print_r($_REQUEST);
echo '<br>COOKIE: ';
print_r($_COOKIE);
echo '</fieldset>';
$temizle =new temizle();
echo '<fieldset><legend>Yeni Hali</legend>';
echo 'POST: ';
print_r($_POST);
echo '<br>GET: ';
print_r($_GET);
echo '<br>REQUEST: ';
print_r($_REQUEST);
echo '<br>COOKIE: ';
print_r($_COOKIE);
echo '</fieldset>';
?>

Çıktısı

---Eski Hali---
POST: Array ( [isim] => Ahmet'in [deger] => Kalem'i ) 
GET: Array ( [id] => nerde' ) 
REQUEST: Array ( [deger] => test" ) 
COOKIE: Array ( [sifre] => 'osman'in_sifresi )
---Yeni Hali---
POST: Array ( [isim] => Ahmet\'in [deger] => Kalem\'i ) 
GET: Array ( [id] => nerde\' ) 
REQUEST: Array ( [deger] => test\" ) 
COOKIE: Array ( [sifre] => \'osman\'in_sifresi )

 

Http Post İsteklerine Erişim Sınıfı

<?php    
header('Content-Type: text/html; charset=utf-8');
class Yayin {
	private static $ornek;
	public static function ornekAl() {
			if (self::$ornek == null) {
					self::$ornek = new Yayin();
			}
			return self::$ornek;
	}
	protected function __construct(){
			foreach($_POST as $key => $value ){
					$this->$key = $value;
			}
	}
	public function __get($isim){
			if (!isSet($this->$isim)){
					$this->$isim= '';
			}
	}
}
$yayin = Yayin::ornekAl();
$deger = $yayin->deger;
$artis = $yayin->artis;
if ($artis == null) {
	$artis = 1;
}
$deger += $artis;
?>
<html>
    <body>
        <form method="POST">
            Arttırılacak Değer: <input type="text" name="deger" value="<?php echo $deger;?>"/>
            <br/>Artış: <input type="text" name="artis" value="<?php echo $artis;?>"/>
            <br/><input type="submit" value="Arttır"/>
        </form>
    </body>
</html>

Çıktısı öne çıkan görseldeki gibidir.

İzin Verilen Sorguları Global Değişken Yapma Sınıfı

<?php
class globalDegisken {
  function globalDegisken ($kabulEdilenDegisken,$sorgu) {
    if (is_array($kabulEdilenDegisken)) {
      $c=count ($kabulEdilenDegisken);
      for ($i=0;$i<$c;$i++) {
				global $$kabulEdilenDegisken[$i];
				if( isset( $_POST[$kabulEdilenDegisken[$i]] ) and ($sorgu == "ALL" or $sorgu == "POST") ) {
					$$kabulEdilenDegisken[$i]=$_POST[$kabulEdilenDegisken[$i]];
				} else if ( isset( $_GET[$kabulEdilenDegisken[$i]]) and ($sorgu == "ALL" or $sorgu == "GET") ) {
					$$kabulEdilenDegisken[$i]=$_GET[$kabulEdilenDegisken[$i]];
				} else {
					$$kabulEdilenDegisken[$i]='';
				}
      }
      return true;
    } else {
      return false;
    }
  }
}
$kabulEdilenDegisken = array("id","user");
$obj = new globalDegisken($kabulEdilenDegisken,"ALL");
print_r($id);
echo "<br>";
print_r($user);
echo "<br>";
print_r($test);
?>

Örnekte id ve user değeri kabul edilen değer olduğu için sonuç verecek,test ise hata verecektir.

index.php?id=1&user=admin&test=a  Çıktısı

1
admin
Notice: Undefined variable: test in index.php on line 28