in reply to Exists with DBM

Thank you Monks.

I have made the suggested changes, but I haven't fixed all the problems. Now I get everything open, but on the server I get a software error with no information as to what the error is. On the CLI I get no error, but the output stops as soon as the script gets into the "if(exists ($allIPs{$userIP}))" loop, it prints the first line, and nothing else. The nested loop just doesn't seem to be activated at all. Any suggestions?

~~Guildencrantz
#!/usr/bin/perl -wT # # Script: Dynamic Dungeon Siege IP Database Activate IP Script # Author: Guildencrantz # Version: 4-13-02 # use strict; use DB_File; use CGI; use CGI::Carp 'fatalsToBrowser'; my $q = new CGI; my $userIP = $q->remote_host; my $allIPsPath = "/var/www/cgi-bin/ds/database/allIPs.db"; my $activeIPsPath = "/var/www/cgi-bin/ds/database/activeIPs.db"; tie my %allIPs, "DB_File", $allIPsPath or die "Cannot open allIPs database: $!"; tie my %activeIPs, "DB_File", $activeIPsPath or die "Cannot open activeIPs database: $!"; print "userIP = $userIP\n"; print "userdata = $allIPs{$userIP}\n"; if( exists $allIPs{$userIP} ) { print "exists in allIPs\n"; if( exists $activeIPs{$userIP} ) { print "exists in activeIPs\n"; print "Content-type: html/text"; print <<END_OF_BLOCK; <HTML> <HEAD> <META HTTP-EQUIV="Refresh" CONTENT="5; URL=/ds +-cgi/viewActive.pl"> <TITLE>ACTIVE</TITLE> </HEAD> <BODY> <H1>Your IP is already marked as active!</H1> <P> <A HREF="/ds-cgi/viewActive.pl"> You will be forwarded in 5 seconds </A> </P> </BODY> </HTML> END_OF_BLOCK } else { print "does not exist in activeIPs\n"; $activeIPs{$userIP} = $allIPs{$userIP}; print "active IPs= $activeIPs{$userIP}\n"; print "Content-type: html/text"; print <<END_OF_BLOCK; <HTML> <HEAD> <META HTTP-EQUIV="Refresh" CONTENT="5; URL=/ds +-cgi/viewActive.pl"> <TITLE>Added!</TITLE> </HEAD> <BODY> <H1>Your IP has been activated!</H1> <P> <A HREF="/ds-cgi/viewActive.pl"> You will be forwarded in 5 seconds </A> </P> </BODY> </HTML> END_OF_BLOCK } } else { print "Content-type: text/html\n\n"; print <<END_OF_BLOCK; <HEAD> <META HTTP-EQUIV="Refresh" CONTENT="5; URL=/ds/submit. +html"> <TITLE>IP Not Registered</TITLE> </HEAD> <BODY> <H1>There is no entry in the database for this IP. You must regis +ter this IP and the associated server attributes</H1> <P> <A HREF="/ds/submit.html"> You will be forwarded in 5 seconds </A> </P> </BODY> </HTML> END_OF_BLOCK } untie %activeIPs; untie %allIPs;

Replies are listed 'Best First'.
Re: Re: Exists with DBM
by grep (Monsignor) on Apr 14, 2002 at 00:14 UTC

    Good, you have identitfied a case that works and one that doesn't (i.e. CLI and browser). Now just narrow down the problems.
    Ask yourself:

  • What am I doing to get it to display on the browser?
  • What does a '500 Server Error' mean (that was your error? wasn't it?).
  • Then you should search your resources for those answers

    I see a couple of problems:

  • You're doing your headers in a manner that could be incorrect or at least inconsistiant.
    print "Content-type: html/text"; print <<END_OF_BLOCK; <HTML>
    This is highly dependant on how your editor does line endings. use  print "Content-type: html/text\n\n"; even better use that CGI module that you loaded  print $q->header();
  • You are printing several things before you print your headers
  • Both of these things will cause a '500 Server Error'. Whenever you see a 500 error, you should check your log file. The log file will generally point you in the right direction

    2 excellent resources for your CGI programming quests:
    tachyon's CGI Help Guide
    Ovid's Ovid's Web Programming with Perl

    grep
    Unix - where you can thrown the manual on the keyboard and get a command