1 2 3 4 5 6 7 8 9
if(($user eq $cgi->param('user')) && ($passwort eq $cgi->param('pwd'))) { $session = new CGI::Session("id:md5", undef, {Directory=>'/tmp'}); # Session erzeugen print "Anmeldung erfolgreich!"; print "Session ID: "; print ($session->id()); # wird nicht angezeigt ! }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
if(($user eq $cgi->param('user')) && ($passwort eq $cgi->param('pwd'))) { $session = new CGI::Session("id:md5", undef, {Directory=>'/tmp'}); # Session erzeugen print "Anmeldung erfolgreich!"; print "Session ID: "; print ($session->id()); # wird nicht angezeigt ! } # wenn Username und Passwort nicht stimmt else { ### DEBUG print STDERR '$user: ', $user, "\n", 'param(user): ', $cgi->param('user'), "\n", '$passwort: : ', $passwort, "\n", 'param(pwd) : ', $cgi->param('pwd'), "\n"; }
$session = new CGI::Session("id:md5", undef, {Directory=>'/tmp'});
1 2 3 4 5 6 7
use strict; use warnings; ### NUR ZUM DEBUGGEN #### ### später unbedingt Zeile mit use CGI::Carp löschen! ### use CGI::Carp qw(fatalsToBrowser warningsToBrowser); #########################################################
1 2 3 4 5 6
BEGIN { use CGI::Carp qw(carpout); open(LOG, '>>', '/var/www/vhosts/meine-website.de/logs/mycgi.log') or die "Unable to open mycgi-log: $!\n"; carpout(LOG); }
2013-03-26T09:34:49 anamollo4musicsobald ich "use CGI::Session;" drin habe, kommt der Serverfehler.
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
#!/usr/bin/perl use strict; use warnings; use CGI::Session; use CGI; my $SIDNAME = CGI::Session->name(); my $cgi = CGI->new; my $sid = $cgi->cookie($SIDNAME) || $cgi->param($SIDNAME) || undef; my $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); } $sid = $session->id; my $cookie = $cgi->cookie( -name => $SIDNAME, -value => $sid ); my $username = $cgi->param('user') || ''; my $password = $cgi->param('pwd') || ''; if ( $username ne '1' or $password ne '1' ) { # Loginparameter falsch print $session->header; print qq( <h1>Login</h1> <form action="?$SIDNAME=$sid" method="POST"> <p> User : <input type="text" name="user"> <br> Passwort: <input type=text name="pwd"> <br> <input type="submit" value="Login"> <input type="hidden" name="$SIDNAME" value="$sid"> </p> </form> ); exit; } else { # Login ok! $session->param( 'user', $username ); $session->param( 'loggedin', 1 ); $session->param( 'lastvisit', "" . localtime() ); print $session->header( -location => "intro.pl?$SIDNAME=$sid", -cookie => $cookie, ); }
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
#!/usr/bin/perl use strict; use warnings; use CGI; use CGI::Session; my $SIDNAME = CGI::Session->name(); my $cgi = CGI->new; my $sid = $cgi->cookie($SIDNAME) || $cgi->param($SIDNAME) || undef; my $session = CGI::Session->load() or die CGI::Session->errstr(); my $logged = $session->param('loggedin'); if ($logged) { my $user = $session->param('user'); my $lasttime = $session->param('lastvisit'); print $session->header, <<HTML; <h1>Varry Sekret Webpadge</h1> <p>Hello <i>$user</i>,<br>you visited us at <tt>$lasttime</tt></p> <p>Pictures : <a href="http://example.org/oaioi/lil-iiii.html">of Lilly</a></p> HTML } else { # Login print $session->header( -location => 'login.pl' ); }
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 106 107
#!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) or die DBI::errstr; my $cgi = new CGI; my $select; my $passwort; my $user; my $i=0; my $session; my $SESSION_EXPIRESAFTER = '+1h'; # nach einer Stunde, notfalls länger 1 W oder 1M my $SIDNAME = CGI::Session->name(); my $sid = $cgi->cookie($SIDNAME) || $cgi->param($SIDNAME) || undef; $session = CGI::Session->load() or die CGI::Session->errstr(); $session->expires($SESSION_EXPIRESAFTER); 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, -httponly => 1, -expires => $SESSION_EXPIRESAFTER, ); $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'))) { $i++; $session->param( 'user',$user ); $session->param( 'loggedin', 1 ); $session->param( 'lastvisit', "" . localtime() ); my $next_url = 'intro.cgi'; print $session->header ( -location => $next_url, -cookie => $cookie ); print "<font face='Arial' size='3' color=#339900><b>Anmeldung erfolgreich! Sie werden weitergeleitet...</b></font>"; 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 "<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> <p>$errormessage</p> <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>";
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
#!perl.exe use strict; use DBI; use CGI; use CGI::Session; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); my $cgi = CGI->new(); my $session = CGI::Session->load() or die CGI::Session->errstr; if (not ($session->param('loggedin') and $session->param('loggedin') == 1 ) ) { #nicht angemeldet!!!! # Weiterleiten zum Login my $next_url = 'login.cgi'; print $session->header ( -location => $next_url ); exit; } # dann ist wohl eingeloggt, also Datenbank abfragen 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) or die DBI::errstr; my $Gesamtsystemquery = $dbh->prepare("select wert from malcos_x;"); my $idMessung; my $Beschreibung; my $Wert; print $cgi->header( -type => 'text/html'); print "<body bgcolor=#bfbfbf>"; print '<p><b><font size=6>Messungen:</font></b></p>'; print "<table border=1>\n"; $Gesamtsystemquery->execute; while(($idMessung, $Beschreibung, $Wert) = $Gesamtsystemquery->fetchrow_array) { print " <tr>\n"; print " <td>System</td>\n"; if($idMessung eq "0") { print "<td>aus</td>\n"; } else { print "<td>ein</td>\n"; } print " <td></td>\n"; print " </tr>\n"; } $Gesamtsystemquery->finish; $dbh->disconnect; print "<br /><br />";