Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Un-helpfull Error

Status
Not open for further replies.

ETbyrne

Programmer
Dec 27, 2006
59
US
Hi, I'm getting a pretty un-helpfull error from my a registration script I made. Here's the error:

Code:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

Error

1

Here's the script:

Code:
#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
use Fcntl qw(:flock :seek);

my $name = param('name') or &error('You have to enter a nickname!');
my $password = param('password') or &error('You have to enter a password!');
my $path = "./mywebs/ETbyrne/rerss/users";
my $shortpath = "./mywebs/ETbyrne/rerss/setup";

open(USER,"<$path/users.pl") or die "could not open users.txt: $!"; #pl extention for security reasons.
my @user_file = <USER>;
close(USER);

foreach my $i (@user_file)
{
  my ($username,$pass) = split(/\|/,$i);
  if($i eq $username)
  {
    &dienice;
  }
}

#+------------------+#
#| Setup Info Files |#
#+------------------+#

# Directory #
mkdir "$users/$name", 0777;


# Password FILE #
open(PASSFILE,">$path/$name/password.pl") or die "Could not create password file: $!";
print PASSFILE "$password\n";
close(PASSFILE);

# Feeds File #
open(FEEDS,"<$shortpath/feeds.txt") or die "Could not create password file: $!";
my @setup_feeds = <FEEDS>;
close(FEEDS);
open(FEEDS,">$path/$name/feeds.txt") or die "Could not create password file: $!";
print FEEDS "@setup_feeds\n";
close(FEEDS);

# List File #
open(LIST,">$path/$name/list.txt") or die "Could not create list file: $!";
close(LIST);

#+----------------------------------+#
#| Setup perl Files and shtml Files |#
#+----------------------------------+#

# index.pl #
open(INDEX,"<$shortpath/index.pl") or die "Could not create index file: $!";
my @setup_index = <INDEX>;
close(INDEX);
open(INDEX,">$path/$name/index.pl") or die "Could not create index file: $!";
print INDEX "@setup_index\n";
close(INDEX);

# add_feed.shtml #
open(ADD,"<$shortpath/add_feed.shtml") or die "Could not create add_feed file: $!";
my @setup_add = <ADD>;
close(ADD);
open(ADD,">$path/$name/add_feed.shtml") or die "Could not create add_feed file: $!";
print ADD "@setup_add\n";
print ADD "<input type=\"hidden\" name=\"author\" value=\"$name\"><\/form><\/body><\/html>\n";
close(ADD);

# delete_feed.shtml #
open(DEL,"<$shortpath/delete_feed.shtml") or die "Could not create delete_feed file: $!";
my @setup_del = <DEL>;
close(DEL);
open(DEL,">$path/$name/delete_feed.shtml") or die "Could not create delete_feed file: $!";
print DEL "@setup_del\n";
print DEL "<input type=\"hidden\" name=\"author\" value=\"$name\"><\/form><\/body><\/html>\n";
close(DEL);

# top.shtml #
open(TOP,"<$shortpath/top.shtml") or die "Could not create top file: $!";
my @setup_top_one = <TOP>;
close(TOP);
open(TOP,">$path/$name/top.shtml") or die "Could not create top file: $!";
print TOP "@setup_top_one\n";
print TOP "<input type=\"hidden\" name=\"author\" value=\"$name\"><\/form><\/body><\/html>\n";
close(TOP);

# top2.shtml #
open(TOP,"<$shortpath/top2.shtml") or die "Could not create top2 file: $!";
my @setup_top_two = <TOP>;
close(TOP);
open(TOP,">$path/$name/top2.shtml") or die "Could not create top2 file: $!";
print TOP "@setup_top_two\n";
print TOP "<input type=\"hidden\" name=\"author\" value=\"$name\"><\/form><\/body><\/html>\n";
close(TOP);

#+--------------+#
#| End of Setup |#
#+--------------+#

print "Location: [URL unfurl="true"]http://www.mywebsfree.com/ETbyrne/rerss/login.shtml\n\n";[/URL]

#+-------------+#
#| Subroutines |#
#+-------------+#

sub dienice{
print "<html><head><link rel=\"stylesheet\" href=\"[URL unfurl="true"]http://www.mywebsfree.com/ETbyrne/rerss/my.css\"[/URL] type=\"text/css\"><\/head><body>\n";
print "<h2>Error<\/h2>\n";
print "That username is already in use. Go back and try another.<\/body><\/html>\n";
exit;
}

sub error{
my $msg = @_;

print "<html><head><link rel=\"stylesheet\" href=\"[URL unfurl="true"]http://www.mywebsfree.com/ETbyrne/rerss/my.css\"[/URL] type=\"text/css\"><\/head><body>\n";
print "<h2>Error<\/h2>\n";
print "$msg <\/body><\/html>\n";
exit;
}

Thanks for all help! ^_^

_______________________________________

You don't know me.
 
Also note: I think it might have something to do with the one of the subroutines but I'm not sure.

_______________________________________

You don't know me.
 
add:

use CGI::Carp qw/fatalsToBrowser/;



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Incidentally: as you're not using file locking anywhere, you have a pile of race conditions in your script, whereby if two people call the script together, you'll get data loss. Also, printing arrays surrounded by double quotes is going to be problematic for you too, as be default you'll be getting a space inserted at the start of every line after the second one.

@travs69: There's a "Location" header to be printed, however if anything dies before that line, that won't happen.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top