Class
İçerisinde extend, __construct, __destruct, __autoload, this, public, private, protected, static, const, cloning object, polimorphism, parent::, self:: ve instanceof gibi class parametleri bulunduran bir uygulama
Formun kodu:
Formun yollandığı islem.php
__autoload, la tanımlandığı zaman yüklenen class (cookie veya session)
cookie classı
Baturay DAYLAK
<html>
<body>
<form action="islem.php" method="post">
<table width="313" align="center"><tr><td width="120">Degisken Tipi</td><td width="181"><select name="tip"><option value="0">Cookie</option><option value="1">Session</option></select></td></tr><tr><td>Degisken Adi</td><td><input type="text" name="ad" /></td></tr><tr><td>Degisken Icerigi</td><td><textarea name="icerik"></textarea></td></tr>
<tr>
<td>Kullanilma Zamani</td>
<td><select name="sure">
<option value="0">30 Dk</option>
<option value="1">1 Saat</option>
<option value="2">1 Gun</option>
</select> </td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Gonder" /></td>
</tr>
</table>
</form>
</body>
</html>
Formun yollandığı islem.php
<?php
function __autoload($class){
require_once("./$class.php");
}
$ad = $_POST['ad'];
$icerik = $_POST['icerik'];
$sure = $_POST['sure'];
$tip = $_POST['tip'];
if($ad=="") $ad="default";
if($icerik=="") $icerik = "default icerik";
switch($sure){
case 0: $sure = 1300;
case 1: $sure = 3600;
case 2: $sure = 3600*24;
}
if($tip==0){
$obj = new cookie(); //cookie nesnesi oluşturuluyor
}
else {
$obj = new session(); //session nesnesi oluşturuluyor
}
if($obj instanceof cookie){ //$obj nesnesi cookie klasına ait bir değerse
$cookie = $obj;
$cookie->ad = $ad;
$cookie->icerik = $icerik;
$cookie->sure = $sure;
$cookie->cookieAtaP();
$cookie->cookieBilgiP();
echo "<br/><br/>Class adi:".cookie::className;
echo "<br/>Class ID:".cookie::classId;
echo "<br/>Parent Adi:".cookie::parentNm();
}
elseif($obj instanceof session){//$obj nesnesi session klasına ait bir değerse
$session = $obj;
$session->ad = $ad;
$session->icerik = $icerik;
$session->sessionAtaP();
$session->sessionBilgiP();
echo "<br/><br/>Class adi:".session::className;
echo "<br/>Class ID:".session::classId;
}
?>
__autoload, la tanımlandığı zaman yüklenen class (cookie veya session)
<?php //session klası
class session
{
public $sure;
public $ad;
public $icerik;
const classId = 9118117;
const className = "Session";
const classScope = "General";
private static $test = "test";
function __construct()
{
echo "Session olusturulmaya basladi...<br/>";
}
private function sessionAc()
{
if(!empty($this->ad) && !empty($this->icerik)){
session_start();
$_SESSION[$this->ad] = $this->icerik;
}
}
public function sessionAtaP()
{
self::sessionAc();
}
private function sessionBilgi()
{
if(!empty($this->ad) && !empty($this->icerik)) echo "Session adi: ".$this->ad."<br>Icerigi: ".$this->icerik;
}
public function sessionBilgiP()
{
self::sessionBilgi();
}
function __destruct()
{
if(!empty($_SESSION[$this->ad])){
if(session_destroy()) echo "<br/>Session kapatildi..".date("d-m-y H:m");
}
}
}
?>
cookie classı
<?php
class cookie extends session
{
const classId = 9118324;
const className = "Cookie";
const classScope = "General";
function __construct()
{
echo "Cookie olusturulmaya baslandi...<br/>";
}
private function cookieAta()
{
if(!empty($this->ad) && !empty($this->icerik)) setcookie($this->ad,$this->icerik,$this->sure);
else echo "Eksik veri girisi. Cookie acilmadi<br/>";
}
private function cookieBilgi()
{
if(!empty($this->ad))
{
echo "<br/>Cookie adi:".$this->ad;
echo "<br/>Cookie icerigi:".$this->icerik;
echo "<br/>Cookie suresi:".$this->sure." sn";
}else echo "Cookie atanmamis<br/>";
}
public function cookieAtaP()
{
$this->cookieAta();
}
public function cookieBilgiP()
{
self::cookieBilgi();
}
public function parentNm()
{
echo parent::className;
}
function __destruct()
{
setcookie($this->ad,NULL,-1);
echo "<br/>Cookie silindi..".date("d-m-y H:m");
}
}
?>
Baturay DAYLAK
Yorumunuzu Ekleyin