Thread Session-ID wird nicht generiert (68 answers)
Opened by anamollo4music at 2013-03-26 08:23

GwenDragon
 2013-03-27 18:30
#166705 #166705
User since
2005-01-17
14542 Artikel
Admin1
[Homepage]
user image
Probier mal das korrigierte login
Code (perl): (dl )
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
#!"C:\xampp\perl\bin\perl.exe"

use strict;

use IO::Handle; 

use DBI;
use CGI;
use CGI::Session;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);

my $dbhost =    "localhost";
my $database =  "sensor";
my $dbuser =    "root";
my $dbpass =    "";

my $dsn = "DBI:mysql:database=$database; host=$dbhost";

my $dbh = DBI->connect($dsn, $dbuser, $dbpass);

my $cgi = new CGI;
my $select;

my $passwort;
my $user;
my $i=0;
my $session;


my $SIDNAME = CGI::Session->name();
my $sid = $cgi->cookie($SIDNAME) || $cgi->param($SIDNAME) || undef;

$session = CGI::Session->load() or die CGI::Session->errstr();
if ( $session->is_empty ) 
{
    $session = CGI::Session->new() or die CGI::Session->errstr();
}
if ( $session->is_expired() ) 
{
    print $session->header(),
        $cgi->start_html(),
        $cgi->p("Your session timed out! Refresh the webpage!"),
        $cgi->end_html();
    exit(0);
}
my $cookie = $cgi->cookie( -name => $SIDNAME, -value => $sid );
$sid = $session->id;

my $errormessage;

if($cgi->param('login'))
{
        $select = $dbh->prepare("select benutzer,passwort from benutzer WHERE benutzer=? AND passwort=?;");
        $select->execute($cgi->param('user'), $cgi->param('pwd'));
        
        
        while(($user, $passwort) = $select->fetchrow_array)
        {
                if(($user eq $cgi->param('user')) && ($passwort eq $cgi->param('pwd')))
                {                        
                        #print "<font face='Arial' size='3' color=#339900><b>Anmeldung erfolgreich! Sie werden weitergeleitet...</b></font>";
                        
                        $i++;
                        $session->param( 'user',$user );
                        $session->param( 'loggedin', 1 );
                        $session->param( 'lastvisit', "" . localtime() );

                        my $next_url = '/localhost/cgi-bin/messung.cgi';
                        print $session->header
                        (
                                -location => "$next_url?$SIDNAME=$sid",
                                -cookie   => $cookie
                        );
                                                exit;
                }       
        }
        if(! $i)                                
        {
                $errormessage = "<font face='Arial' size='3' color=#CC3300><b>Anmeldung fehlgeschlagen!</b></font>";
        }
}   

print $session->header( -type => 'text/html'); 

print "<html><head><meta http-equiv='content-type' content='text/html; charset=utf-8' /><link rel='stylesheet' media='screen,projection' type='text/css' href='/css/main.css' /><link rel='stylesheet' media='screen,projection' type='text/css' href='/css/scheme.css' />";
print "</head>";
print "<body>";
print "<p>$errormessage</p>";
print "<form action='/cgi-bin/login.cgi' method='post'><div id='main'>";
print "<div id='footer'> 
        <h1 id='logo'><a>sensor.<span>ct</span></a></h1>
        <hr class='noscreen' />        
        </div> ";

                
print "<div id='navlogin'><ul class='box'><br><li><p><font face='Arial' size='6'><b>Login</b></font></p> <br><blockquote>Benutzer-ID: <br><input type='text' size='30' name='user'></li></ul><br><ul class='box'><li><blockquote>Kennwort: <br><input type='password' size='30' name='pwd'></li></ul>";         
print "<br><ul class='box'><li><blockquote><br><input class='button' type='submit' name='login'  value='Einloggen'></li><br></ul></div> ";
print "</body></html>";

    
die Drachin, Gwendolyn


Unterschiedliche Perl-Versionen auf Windows (fast wie perlbrew) • Meine Perl-Artikel

View full thread Session-ID wird nicht generiert