phpmysql-inlog-functie
Gesponsorde koppelingen
PHP script bestanden
Code (php)
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
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
<?php
/*
Made by : Robin Hozee
License : OGL
Source : Public
$website =''; //Website name
$domain =''; //Domain
$path =''; //path of the website on domain
$expire =''; //Time for cookie to expire in seconds
Supports the following actions
login : Form action target.php?action=login
logout : Option when logged in, url target.php?action=logout
and continued renewal of cookie + cookiehash when logged in.
$name and $pass should be extracted from the loginform
This function assumes that there is already a connection to the database.
Required SQL;
CREATE TABLE `users` (
`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 '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
*/
function usersession($website,$domain,$path,$expire)
{
global $action;
global $name;
global $pass;
if($action == "login")
{
$selectsql = 'SELECT * FROM users WHERE name="'.$name.'" AND password="'.md5($pass).'"';
$rows = mysql_num_rows(mysql_query($selectsql));
if($rows == 1)
{ $timehash = md5(time());
$update = 'UPDATE users SET timehash="'.$timehash.'", ip="'.$_SERVER[REMOTE_ADDR].'" WHERE name="'.$name.'"';
mysql_query($update);
setcookie($website, $timehash, time()+$expire, $path, $domain, "0");
}
if($rows == 0)
{
}
echo "<script>location.href='/'</script>";
}
if($action == "logout")
{
$update = 'UPDATE users SET timehash="logout" WHERE ip="'.$_SERVER[REMOTE_ADDR].'"';
mysql_query($update);
}
else
{
$selectsql = 'SELECT * FROM users WHERE timehash="'.$_COOKIE[$website].'" AND ip="'.$_SERVER[REMOTE_ADDR].'"';
$select = mysql_query($selectsql);
$rows = mysql_num_rows($select);
if($rows > 0)
{
$user = mysql_fetch_array($select);
$timehash = md5(time());
$update = 'UPDATE users SET timehash="'.$timehash.'" WHERE ip="'.$_SERVER[REMOTE_ADDR].'"';
mysql_query($update);
setcookie($website, $timehash, time()+$expire, $path, $domain, "0");
return $user;
}
}
}
?>
/*
Made by : Robin Hozee
License : OGL
Source : Public
$website =''; //Website name
$domain =''; //Domain
$path =''; //path of the website on domain
$expire =''; //Time for cookie to expire in seconds
Supports the following actions
login : Form action target.php?action=login
logout : Option when logged in, url target.php?action=logout
and continued renewal of cookie + cookiehash when logged in.
$name and $pass should be extracted from the loginform
This function assumes that there is already a connection to the database.
Required SQL;
CREATE TABLE `users` (
`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 '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
*/
function usersession($website,$domain,$path,$expire)
{
global $action;
global $name;
global $pass;
if($action == "login")
{
$selectsql = 'SELECT * FROM users WHERE name="'.$name.'" AND password="'.md5($pass).'"';
$rows = mysql_num_rows(mysql_query($selectsql));
if($rows == 1)
{ $timehash = md5(time());
$update = 'UPDATE users SET timehash="'.$timehash.'", ip="'.$_SERVER[REMOTE_ADDR].'" WHERE name="'.$name.'"';
mysql_query($update);
setcookie($website, $timehash, time()+$expire, $path, $domain, "0");
}
if($rows == 0)
{
}
echo "<script>location.href='/'</script>";
}
if($action == "logout")
{
$update = 'UPDATE users SET timehash="logout" WHERE ip="'.$_SERVER[REMOTE_ADDR].'"';
mysql_query($update);
}
else
{
$selectsql = 'SELECT * FROM users WHERE timehash="'.$_COOKIE[$website].'" AND ip="'.$_SERVER[REMOTE_ADDR].'"';
$select = mysql_query($selectsql);
$rows = mysql_num_rows($select);
if($rows > 0)
{
$user = mysql_fetch_array($select);
$timehash = md5(time());
$update = 'UPDATE users SET timehash="'.$timehash.'" WHERE ip="'.$_SERVER[REMOTE_ADDR].'"';
mysql_query($update);
setcookie($website, $timehash, time()+$expire, $path, $domain, "0");
return $user;
}
}
}
?>