Leser: 1
|< 1 2 >| | 19 Einträge, 2 Seiten |
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
sub check_sid {
my $login = shift;
my $usr_id = shift;
my $sid = param('SID');
#load old sid by GET-param()
my $dbh = dbi_connection();
$CGI::Session::MySQL::TABLE_NAME = 'sessions';
my $session = CGI::Session->load("driver:mysql", $sid, {Handle=>$dbh})
or die CGI::Session->errstr;
if ($session->is_expired) {
print 'Deine SessionID ("', $sid ,'") ist abgelaufen, bitte <a href="sprechstunde.cgi">logge dich neu ein</a>!';
del_session($sid);
exit 0;
}
#only while login we can have a empty sid
if ($session->is_empty) {
if ($login) {
del_session(undef, $usr_id);
$session = $session->new();
$session->expire('+10s');
create_session($session->id, $usr_id);
} else {
my $tmpl = HTML::Template::Compiled->new(filename => '../templates/sp_login.htc');
print $tmpl->param(PROB =>"Session-ID Problem!<br />\n");
print $tmpl->output(), "\n";
exit 0;
}
}
return $session->id;
}#sub check_sid()
sub del_session {
my ($sid, $usr_id) = @_;
my $dbh = dbi_connection();
my $statement;
if ($sid) {
$statement = "DELETE FROM sessions WHERE id=?";
} elsif ($usr_id) {
$statement = "DELETE FROM sessions WHERE user_id=?";
}
my $sth = $dbh->prepare($statement);
$sth->execute($sid?$sid:$usr_id) or die $DBI::errstr;
$dbh->disconnect() or die $DBI::errstr;
}#sub del_session()
sub create_session {
my ($sid, $usr_id) = @_;
my $dbh = dbi_connection();
my $sth = $dbh->prepare("UPDATE sessions SET user_id=? WHERE id=?");
$sth->execute($usr_id, $sid) or die $DBI::errstr;
$dbh->disconnect() or die $DBI::errstr;
}
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
mysql> select * from sessions;
+----------------------------------+------------------------------------------------------
------------------------------------------------------------------------------------------
--------------------------------------------+---------+
| id | a_session | user_id |
+----------------------------------+------------------------------------------------------
------------------------------------------------------------------------------------------
--------------------------------------------+---------+
| 90cf21a276ec8d99c0cb019f064dbab9 | $D = {'_SESSION_ETIME' => 30,'_SESSION_ID' => '90cf21a276ec8d99c0cb019f064dbab9','_SESSION_ATIME' => 1170677065,'_SESSION_REMOTE_ADDR' => '127.0.0.1','_SESSION_CTIME' => 1170677065};;$D | 0 |
| 639013b448946598f00e83c98d91887b | $D = {'_SESSION_ETIME' => 10,'_SESSION_ID' => '639013b448946598f00e83c98d91887b','_SESSION_ATIME' => 1170677541,'_SESSION_REMOTE_ADDR' => '127.0.0.1','_SESSION_CTIME' => 1170677541};;$D | 0 |
| 26e4aa9a35028c8863b732ebaa512308 | $D = {'_SESSION_ETIME' => 600,'_SESSION_ID' => '26e4aa9a35028c8863b732ebaa512308','_SESSION_ATIME' => 1170677579,'_SESSION_REMOTE_ADDR' => '127.0.0.1','_SESSION_CTIME' => 1170677579};;$D | 0 |
+----------------------------------+------------------------------------------------------
------------------------------------------------------------------------------------------
--------------------------------------------+---------+
3 rows in set (0.00 sec)
1
2
3
4
5
6
7
sub check_sid {
...
$statement = "DELETE FROM sessions WHERE(id='$sid')";
...
my $sth = $dbh->prepare("UPDATE sessions SET user_id='$usr_id' WHERE(id='$sid')");
$sth->execute() or die $DBI::errstr;
}
|< 1 2 >| | 19 Einträge, 2 Seiten |