Thread: New approach
View Single Post
Old 05-22-2008, 12:31 PM   #28 (permalink)
bedri
The Visitor
 
Join Date: May 2008
Posts: 2
Thanks: 1
bedri is on a distinguished road
Default

What i did in my session-db combined login class in vo.php file is
PHP Code:
<?php
error_reporting
(E_ALL);
@
ini_set("display_errors","1");

require_once(
"database.php");
require_once(
"session.php");
require_once(
"izinler.php");

class 
login
{
var 
$username;
var 
$password;
var 
$userid;
var 
$user_enable;
var 
$oturumid;

function 
login()
{
global 
$db;
global 
$session;

    
$db = new database;
    
$db->setUser("root","");
    
$db->setDatabase("viyatek");

    
$db->query("SET NAMES 'utf8'");
    
$db->query("SET collation_connection = 'utf8_turkish_ci'");


    
$session = new session;
    
$this->oturumid $session->session_id;
}

    
/*
     * Genel kullanimda iki sozcugun match'i icin fonksiyon. Ozel olarak burada gonderilen username'in
     * veritabanindaki sifresini gonderilen sifre ile match ediyor.
     */
    
function checker($username,$password,$posta_adi="1")
    {
    global 
$db;
    global 
$session;

    
$this->username $username;
    
$this->password $password;

    
$user_que $db->query("SELECT * FROM userdata WHERE username='$this->username'");
    
$user_list $db->result();

    
$this->userid $user_list['id'];
    
$this->username $user_list['username'];
    
$this->ad_soyad $user_list['ad'] . ' ' $user_list['soyad'];
    
$this->user_level $user_list['level'];
    
$this->user_switchno $user_list['switchno'];
    
$this->user_onuno $user_list['onuno'];

    
$oturum_que $db->query("SELECT * FROM sessions WHERE userid='$this->userid';");

        if( ( 
$posta_adi == "1" ) && ( $this->password != "" ) && ( $this->username != "" ) )
        {
            if( 
$this->user_enable != constant("ADMIN") )
            {
                if ( 
$this->user_level == constant("BANNED") )
                {
                    
header("Location: user_banned.php");
                    exit();
                }
    
                if ( 
$db->num_rows($oturum_que) && ($this->userid != "2") )
                {
                    
$session->destroy();
                    
header("Location: duplicate_user.php");
                    exit();
                }
            }

            if( 
$this->password == $user_list['password'] )
            {
                
$session->set("userid",$this->userid);
                
$session->set("username",$this->username);
                
$session->set("user_level",$this->user_level);
                
$session->set("adsoyad",$this->ad_soyad);
                
$session->set("sepet","0_0");
                
$session->set("oturum","1");
                
$session->set("user_switchno",$this->user_switchno);
                
$session->set("user_onuno",$this->user_onuno);

                
$session->set("mac_filtering_macid","0");
                
$session->set("mac_filtering_vlanid","0");
                
$session->set("static_mac_filtering_macid","0");
                
$session->set("static_mac_filtering_vlanid","0");
                
$session->set("mac_filtering_gid","0");

                
$db->query("UPDATE sessions SET userid='$this->userid' WHERE id='$this->oturumid';");
                
header("Location: index.php");
                exit();
            }
            else
            {
                
header("Location: kullanici_giris.php");
                exit();
            }
        }
    }

    
/*
     *Oturum acilmismi kontrolu
     */
    
function kontrolcu()
    {
    global 
$db;
    global 
$session;
        if(
$session->get("oturum") != "1")
        {
            
//$this->eslestirici("guest","guest","1");
            //header("Location: index.php");
            
header("Location: kullanici_giris.php");
        }
        else return 
1;
    }
}
?>
and for the index.php part
PHP Code:
<?php
ob_start
();
error_reporting(E_ALL);
@
ini_set('display_errors','1');
require_once(
"kutuphane/vo.php");
$login = new login;
$login->kontrolcu();
?>
That's all. If you go pages by lettin index.php calls the files then your session and database objects as well as the login object will work really fine.
bedri is offline  
Reply With Quote