authenticatie-class

Gesponsorde koppelingen

PHP script bestanden

  1. authenticatie-class

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?

class mysession
    {
    //MYSQL VARS
    var $mysqlhost;        //mysql server adress
    var $mysqluser;        //mysql server user
    var $mysqlpass;        //mysql server password
    var $mysqldb;        //mysql database
    
    //COOKIE VARS

    var $website;        //website name
    var $path;            //cookiepath, leave empty
    var $domain;        //website domain
    var $expire;        //cookie expire time in seconds
    
    //CONFIG VAR

    var $defaultpath;    //Default path after logout/failed login
    
    function SetVars ($mysql,$cookie,$config)
        {

        //MYSQL VARS
         $this->mysqlhost=$mysql['host'];
         $this->mysqluser=$mysql['user'];
         $this->mysqlpass=$mysql['pass'];
         $this->mysqldb=$mysql['db'];
        //COOKIE VARS
        $this->website=$cookie['website'];
        $this->path=$cookie['path'];
         $this->domain=$cookie['domain'];
         $this->expire=$cookie['expire'];
        //CONFIG VARS
        $this->defaultpath=$config['path'];
        }
            
    function
db_connect()
        {

        $conn = mysql_connect($this->mysqlhost,$this->mysqluser,$this->mysqlpass) or die ("Unable to connect to database");
        $db   = mysql_select_db($this->mysqldb,$conn) or die ("Unable to connect to database");
        }
    
    function
createtable()
        {

        $sql =
            '
            CREATE TABLE `mysession`
                (
                `id` int(4) NOT NULL auto_increment,
                `name` varchar(20) NOT NULL default \'\',
                `password` varchar(32) NOT NULL default \'\',
                `timehash` varchar(32) NOT NULL default \'\',
                `ip` varchar(20) NOT NULL default \'\',
                `firstname` varchar(50) NOT NULL default \'\',
                `surname` varchar(20) NOT NULL default \'\',
                `email` varchar(50) NOT NULL default \'\',
                PRIMARY KEY  (`id`)
                )
            TYPE=MyISAM AUTO_INCREMENT=1            
            '
;
        $return = mysql_query ($sql);
        }
        
    function
login($name, $pass)
        {

        $sql = 'SELECT * FROM mysession WHERE name="'.$name.'" AND password="'.md5($pass).'"';
        $rows = mysql_num_rows(mysql_query($sql));
        if($rows == 1)  
            {

            $timehash = md5(time());
            $update = 'UPDATE mysession SET timehash="'.$timehash.'", ip="'.$_SERVER[REMOTE_ADDR].'" WHERE name="'.$name.'"';
            mysql_query($update);
            setcookie($this->website, $timehash, time()+$this->expire, "", $this->domain, "0");
            }

        if($rows == 0)
            {

            echo '<script>location.href="'.$this->defaultpath.'"</script>';
            }
        }
    
    function
check()
        {

        global $name;
        global $pass;
        $sql = 'SELECT * FROM mysession WHERE timehash="'.$_COOKIE[$this->website].'" AND ip="'.$_SERVER[REMOTE_ADDR].'"';
        $select = mysql_query($sql);
        $rows = mysql_num_rows($select);
        if($rows > 0)  
            {

            $user = mysql_fetch_array($select);
            $timehash = md5(time());
            $update = 'UPDATE mysession SET timehash="'.$timehash.'" WHERE ip="'.$_SERVER[REMOTE_ADDR].'"';
            mysql_query($update);
            setcookie($this->website, $timehash, time()+$this->expire, "", $this->domain, "0");
            return $user;
            }
        }
        
    function
logout()
        {

        $update = 'UPDATE mysession SET timehash="'.md5(time()).'" WHERE ip="'.$_SERVER[REMOTE_ADDR].'" AND timehash="'.$_COOKIE[$this->website].'"';
        mysql_query($update);
        echo '<script>location.href="'.$this->defaultpath.'"</script>';
        }
    }

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.