v2.5.2
Giriş yap

Üye Giriş/Çıkış Session Class'ı Oluşturma

coder
360 defa görüntülendi

Herkese merhaba.
Aşağıdaki gibi bir class yapısı var.
Admin ve üye girişi için. Ama daha sade ve kullanılabilir nasıl yapılabilir sizce?


<?php

class SessionManager extends Model
{
    static function CreateSession($array = [])
    {
        $_SESSION["Login"] = true;
        foreach ($array as $key => $value){
            $_SESSION[$key] = $value;
        }
    }
    
    static function DeleteSession($key)
    {
        unset($_SESSION[$key]);
    }
    
    static function DeleteAllSession()
    {
        session_destroy();
    }

    public function IsLogin()
    {
        if( isset($_SESSION["uye_kullanici_adi"]) and isset($_SESSION["uye_sifre"]) ){

            $uye_adi = $_SESSION["uye_kullanici_adi"];
            $uye_sifre = $_SESSION["uye_sifre"];

            $data = [
                "uye_adi" => $uye_adi,
                "uye_sifre" => $uye_sifre
            ];

            $this->db->query("SELECT * FROM uyeler WHERE uye_kullanici_adi = :uye_adi && uye_sifre = :uye_sifre",$data);

            $this->db->execute();

            if($this->db->rowCount() != 0){
                return true;
            }else{
                return false;
            }

        }else{
            return false;
        }
    }
    
    public function UserInfo()
    {
        if($this->IsLogin()){

            $uye_adi = $_SESSION["uye_kullanici_adi"];
            $uye_sifre = $_SESSION["uye_sifre"];

            $data = [
                "uye_adi" => $uye_adi,
                "uye_sifre" => $uye_sifre
            ];

            $this->db->query("SELECT * FROM uyeler WHERE uye_kullanici_adi = :uye_adi && uye_sifre = :uye_sifre",$data);

            return $this->db->fetch();
            
        }else{
            return false;
        }
    }

    public function AdminIsLogin()
    {
        if( isset($_SESSION["yonetici_kullanici_adi"]) and isset($_SESSION["yonetici_sifre"]) ){

            $yonetici_adi = $_SESSION["yonetici_kullanici_adi"];
            $yonetici_sifre = $_SESSION["yonetici_sifre"];

            $data = [
                "yonetici_adi" => $yonetici_adi,
                "yonetici_sifre" => $yonetici_sifre
            ];

            $this->db->query("SELECT * FROM yoneticiler WHERE yonetici_kullanici_adi = :yonetici_adi && yonetici_sifre = :yonetici_sifre",$data);

            $this->db->execute();

            if($this->db->rowCount() != 0){
                return true;
            }else{
                return false;
            }

        }else{
            return false;
        }
    }

    public function AdminInfo()
    {
        if($this->AdminIsLogin()){

            $yonetici_adi = $_SESSION["yonetici_kullanici_adi"];
            $yonetici_sifre = $_SESSION["yonetici_sifre"];

            $data = [
                "yonetici_adi" => $yonetici_adi,
                "yonetici_sifre" => $yonetici_sifre
            ];

            $this->db->query("SELECT * FROM yoneticiler WHERE yonetici_kullanici_adi = :yonetici_adi && yonetici_sifre = :yonetici_sifre",$data);

            return $this->db->fetch();

        }else{
            return false;
        }
    }
}

// Kullanım

// Session Oluştur
SessionManager::CreateSession(
	['yonetici_kullanici_adi' => $kadi, 'yonetici_sifre' => md5($sifre)]
);

// Session sil
SessionManager::DeleteSession("Login");

// Sessionların tümünü sil
SessionManager::DeleteAllSession();

?>
Cevap yaz
Cevaplar (0)
Henüz kimse cevap yazmadı. İlk cevap yazan sen ol!