/CGI : Formularüberprüfung funktioniert nicht ?
xNeTworKx
- javascript
Hallo, Zu meinem Entsetzen bin ich heute zufällig draufgekommen, daß die Formularüberprüfung eines CGI Scripts, daß Links hinzufügen kann, nicht funktioniert. Das Dumme ist, ich weis einfach nicht wieso ? DIe Variablen stimmen alle überein. Der Funktionsname stimmt überein. Ich hatte vorher das JS in einer seperaten Datei, habe es jetzt ins Script geschrieben, da ich zuerst vielleicht dachte, daß das CGI Script irgendwie mit den ../ Pfaden oder so nicht klar kommt, was aber nicht der Fall ist. Die Überprüfung findet einfach nicht statt und weis nicht wieso. Ich wäre froh wenn jemand den Fehler finden kann. Hier das Script:
#!C:/Perl/bin/Perl -w
use strict; use CGI::Carp qw(fatalsToBrowser); use CGI::Cookie; use CGI;
my $url = 'http://212.17.119.105/acid4u/links/links.cgi'; my $query = new CGI; my $ip = $ENV{'REMOTE_ADDR'}; my $admin = '255.255.255.255'; my $moderator = '255.255.255.255';
if ($query->param('action')) { my $action = $query->param('action'); if ($action eq 'links') { links(); } if ($action eq 'savelink') { my $sessioncookie = ''; my $linktext = $query->param('text');
if (readsessioncookie()) { print $query->redirect("$url"); } else { savesessioncookie4links($sessioncookie); savelink($linktext,$sessioncookie); } } if ($action eq 'deletelink') { my $link = $query->param('text'); deletelink($link); }
} else { links(); }
sub links { print $query->header; print <<EOF; <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <meta http-equiv="Content-Style-Type" content="text/css"> <link rel="stylesheet" type="text/css" href="../hauptdaten.css"> <script type="text/javascript"> function chkformular() { if (document.formular.text.value == "") { alert('Es wurde kein Link eingetragen !'); document.formular.text.focus(); return false; } if (document.formular.text.value.substring(0, 7) != 'http://') { if (document.formular.text.value.substring(0, 6) != 'ftp://') { alert('Der Link muss mit 'http://' oder 'ftp://' anfangen !'); document.formular.text.focus(); return false; } } } </script> <title>acid4u.com links</title> </head> <body> <table style="border:0px; width:750px"> EOF
if (-e 'links.txt') { my $in = ''; open(FILE,"links.txt") or die "Cant open link database : $!\n"; local $/; $in = <FILE>;
while ($in =~ /<link>(.+?)</link>/g) { print "<tr><td class="left"><a href="$1" target="parent">$1</a></td></tr>\n"; } } close FILE; print <<EOF; </table> <form method="post" name="formular" action="" onSubmit="return chkformular()"> <table style="border:0px"> <colgroup> <col width="50%"> <col width="50%"> </colgroup> <tr><td colspan="2"><input type="text" class="link" name="text" maxlength="500"></td></tr> <tr><td>Hier kannst du neue Links hinzufügen :</td><td class="middle"><input type="hidden" name="action" value="savelink"><input type="submit" class="linkbutton" name="action" value="hinzufügen"></td></tr> </table> </form> </body> </html> EOF
if ($ip eq "$admin" || $ip eq "$moderator") { print <<EOF; <form method="post" name="formular" action=""> <table style="border:0px"> <colgroup> <col width="50%"> <col width="50%"> </colgroup> <tr><td colspan="2"><input type="text" class="linkrot" name="text" maxlength="500"></td></tr> <tr><td><span style="color:#FF0000">Diesen Link löschen :</span></td><td class="middle"><input type="hidden" name="action" value="deletelink"><input type="submit" class="linkbuttonrot" name="action" value="löschen"></td></tr> </table> </form> EOF
} } sub savelink { my ($linktext,$sessioncookie) = @_; open(FILE,">>links.txt") or die "Cant open linkdatabase : $!\n"; flock FILE, 2; print FILE "<link>$linktext</link>\n"; close FILE;
print $query->header(-cookie=>$sessioncookie, -location=>"$url");
}
sub savesessioncookie4links { my $sessioncookie = shift; $$sessioncookie = $query->cookie(-name => 'sessioncookie', -value => 'sessioncookie', -expires => '+5s', -path => '/');
}
sub readsessioncookie { my %cookies = fetch CGI::Cookie; foreach (keys %cookies) { if (($cookies{$_}) =~ /sessioncookie/) { return 1; } } } sub deletelink { my $link = shift; my $in = ''; my @links = (); my $counter = 0;
if (-e 'links.txt' && $link ne '') { open(FILE,'links.txt') or die "Cant delete Link from database : $!\n"; while (<FILE>) { $in .= $_; } close FILE;
while ($in =~ /(<link>.+?</link>)/g) { push @links, $1; } foreach my $pos(@links) { if ($pos =~ /$link/) { splice(@links, $counter, 1); } $counter++; } open(FILE,'>links.txt') or die "Cant modify database : $!\n"; flock FILE, 2; print FILE "@links\n"; close FILE; } print $query->redirect("$url"); }
Hi nochmal
alert('Der Link muss mit 'http://' oder 'ftp://' anfangen !);
' gefällt ihm nicht =)