FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


stupid mistake?





tester9
hi to all,
since 5 days i'am searching for the bug in my perl script.
Perhaps I did save it after clearing one sign...
And now, i am not abe fo find it. And the website don't show an error like 'Mistake in line 12' or something like else.

Here is the code:

#!/usr/bin/perl -w
use strict;
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use CGI::Cookie;

my $header = "Content-type: text/html\n\n";

# cookies holen
my %cookies;
my $login;
%cookies = fetch CGI::Cookie;
$login = $cookies{'IDLOGIN'}->value;



### Datum und Zeit umrechnen

sub umrechnen {

my $zeit = $_[0];

my @realtime;
@realtime = spit (/\s+/,$zeit);

my $wochentagtag=@realtime[0];
my $monat = @realtime[1];
my $tag = @realtime[2];
my $zeit=@realtime[3];
my $jahr=@realtime[4];

my @realhour = split (/:/,$zeit);
my $stunde = @realhour[0];
my $minute = @realhour[1];
my $sekunde = @realhour[2];

if ($stunde <= 17)
{
$stunde=$stunde+7;
}
else
{
$stunde=$stunde-15;
}

my $ergebniss = "(".$tag." ".$monat." ".$jahr." ".$stunde.":".$minute.":".$sekunde.")";
return $ergebniss;
}

### und daten einlesen!

if ($login eq "adm_usr") {

open (DATEI,"../cgi-bin/data/buch.txt");
my @daten;
@daten = <DATEI>;
close DATEI;

### seite erstellen

my $seite;
$seite = <<dasende
<html>
<head>
<title>Adminconsole</title>
</head>
<link rel="stylesheet" type="text/css" href="../styles/crystal/style.css">
<body>
<br>
<div align="center"><a href="../cgi-bin/anzeigen.pl">back?</a></div>
<div align="center"><a href="#tabelle_logbuch">Logbuch?</a></div>
<div align="center"><a href="#tabelle_angemeldet">wer ist angemeldet?</a></div>
<br>
<br>
LoginPasswort zurücksetzen (bei \$login): <br>
<form action="../cgi-bin/adm_new.pl" method="" target="">
<input type="Text" name="login_reaktivieren" value="" size="" maxlength="">
<input type="Submit" name="ok" value="Zurücksetzen">
</form>
<br>
<br>
<hr noshade size="1">
<table align ="center">
dasende
;

#und ausgeben
print $header.$seite;
print "<a name = 'tabelle_logbuch'>";

#variablenbelegungen/definitionen dazu
my @loginliste;
my @angemeldet;
my @datenkopie = @daten;
my $wielang = @daten;
my $wielangneu= $wielang-250; #zahl gibt anzahl der logbucheinträge an, wenn zu lang...;
my $i;

while($i <= $wielangneu)
{
shift @daten;
$i++;
}

### Logintabelle ausgeben, allways in strukture

foreach my $eintrag (@daten) {
@loginliste = split (/\s*-\|-\s*/,$eintrag);
print "<tr>"."<td>".@loginliste[0];
push @angemeldet,@loginliste[0];
open (DATEI,"../cgi-bin/".@loginliste[0].".pwd");
my @userdaten;
@userdaten = <DATEI>;
close DATEI;
my $dummy= shift @userdaten;
my $realpw= shift @userdaten;


#und Passwörter überprüfen, wenn rot, falsch sonst grün
if ($realpw eq @loginliste[1]."\n"){
print "<td><font color='green'>".@loginliste[1]."</font><td>".&umrechnen(@loginliste[2])."</tr>";
}
else{
print "<td><font color='red'>".@loginliste[1]."</font><td>".&umrechnen(@loginliste[2])."</tr>";
}
}

print "</table>";

print "<hr noshade size='1'>";

###und alle angemeldeten zeigen!!!

@angemeldet = sort @angemeldet;
my @neuangemeldet;
my $tmp;
my $zaehler;
my $neuzaehl;

foreach $neuzaehl (@angemeldet){
if ($tmp ne $neuzaehl) {
push @neuangemeldet, $neuzaehl;
$tmp = $neuzaehl;
$zaehler++;
}
}

print "<a name = 'tabelle_angemeldet'>";
print "<table align='center'>";
print "<tr><td><h2>Angemeldet sind $zaehler (letzte 250 logbucheinträge)</h2></td></tr>";
foreach my $dummy (@neuangemeldet){
print "<tr><td>".$dummy."</td></tr>";
}
print "</table>";
print "</body>";
print "</html>";
}

### login verbieten, wenn username fasch...

if ($login ne "adm_usr") {

my $seite;
$seite = <<endeende
<html>
<head>
<title>Adminconsole</title>
</head>
<link rel="stylesheet" type="text/css" href="../styles/crystal/style.css">
<body>
not authorisized!
</body>
</html>
endeende
;

print $header.$seite;
}

Arrow
deepak
Hi, I found mistake in your way to use cookies. First you have to create an empty cookie or dummy cookie and then send it yo header like this

Code:

#!/usr/bin/perl

use CGI qw/:standard/;
use CGI::Cookie;

# Create new cookies and send them
    $cookie1 = new CGI::Cookie(-name=>'IDLOGIN',-value=>123456);
    $cookie2 = new CGI::Cookie(-name=>'preferences',
                               -value=>{ font => Helvetica,
                                         size => 12 }
                               );
    print header(-cookie=>[$cookie1,$cookie2]);

    # fetch existing cookies
    %cookies = fetch CGI::Cookie;
    $login= $cookies{'IDLOGIN'}->value;

    # create cookies returned from an external source
    %cookies = parse CGI::Cookie($ENV{COOKIE});


After this you can write your leftover code, make sure you dont print HEADER AGAIN and ALL FILES which you are using in your file MUST exist with proper permissions.

See this http://deepak.frih.net/cgi-bin/test_perl.cgi

Goodluck! Danke
tester9
Yes, you are right.
But the cookie is been sending to header by another script.
With the script itselb I only wantet to fetch them because of login information.

But yesterday I found the stupid mistake myself.
I have written spit, but wantet so write split.
While spit is not a command, the compiler shows an error!!! Wink

But thx a lot for helping me !!!
tester9
added: it was in the passage where i splitted the time

sub umrechnen {

my $zeit = $_[0];

my @realtime;
@realtime = spit (/\s+/,$zeit);

my $wochentagtag=@realtime[0];
my $monat = @realtime[1];
my $tag = @realtime[2];
my $zeit=@realtime[3];
my $jahr=@realtime[4];

my @realhour = split (/:/,$zeit);
my $stunde = @realhour[0];
my $minute = @realhour[1];
my $sekunde = @realhour[2];

if ($stunde <= 17)
{
$stunde=$stunde+7;
}
else
{
$stunde=$stunde-15;
}

my $ergebniss = "(".$tag." ".$monat." ".$jahr." ".$stunde.":".$minute.":".$sekunde.")";
return $ergebniss;
}
deepak
haha .. even i also overlooked "SPIT". Deubuging perl scripts are a headache. Goodluck.
Related topics
Ok a little help for a semi-beginner
didnt receive password email
few Laptop questions...
science vs. religion
Next generation consoles...
Does anyone believe that the U.S. is a corrupt government?
Have you ever dumped someone and realized it was a mistake?
Frihost server (1) still banned by aol (mail) as spam ?
Mathematical breakthrough: Zero defined!
Form Hit Counter
Over clocking help
Privitize Your Downloads.
Mysql data recovery...rather urgent!
The Middle East Conflict
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.