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!

Odd Error

Status
Not open for further replies.

ETbyrne

Programmer
Dec 27, 2006
59
US
Hi, I'm getting an odd error with my script, here's the error:

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

Could not open dir portals: No such file or directory at e:\0\74\38\237038\user\240783\htdocs\mywebs\ETbyrne\portal\regester.pl line 25.

Ok, the dir "portals" does exist, here's my script:

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

my $author = param('author') or die "You have to enter a Nick Name.";
my $password = param('password') or die "You have to enter a Password.";
my $email = param('email') or die "You have to enter your e-mail.";

open(FILE, ">>./mywebs/ETbyrne/portal/authorlist.txt") or die "Can't open authorlist.txt: $!";
seek(FILE,0,0);
my @file = <FILE>;
chomp(my $key = $author);

foreach my $el (@file)
  {
  chomp($el);
  if ($key eq $el)
    {
      print "That username allready exist, click back and try a different one\n";
      exit;
    }
  }
chdir "portals" or die "Could not open dir portals: $!";
mkdir $author, 0777;
chdir "$author" or die "Could not open dir portals\/$author";

open(FH, ">>./mywebs/ETbyrne/portal/authorlist.txt") or die "Error opening author list";
flock(FH,LOCK_EX);
seek(FH,0,2);
print FH "$author\n";
close FH;

open(FILE, ">>./mywebs/ETbyrne/portal/$author/password.txt") or die "Error makeing password";
print FILE "$password\n";
close FILE;

open(FILE,">>./mywebs/ETbyrne/portal/$author/email.txt") or die "Could not write email file: $!";
print FILE "$email\n";
close FILE;

print "Content-type: text/html\n\n";
print "<html><head><title>Portal Manager</title></head>\n";
print "<body bgcolor=\"silver\">\n";
print "<h2>Welcome, $author !</h2>\n";
print "<hr>\n";
print "You have completed regestration!<br>\n";
print "<input type=\"hidden\" name=\"password\" value=\"$password\"><input type=\"hidden\" name=\"author\" value=\"$author\">\n";

print "</body></html>\n";

_______________________________________

You don't know me.
 
Your problem is with this line:

Code:
chdir "portals" or die "Could not open dir portals: $!";

Specify an absolute path instead. The current working directory is obviously not what you expect, which makes sence since it's running under the web server.

-M
 
I would also say you should use full paths everywhere. You shouldn't rely on where you script is running from to find directories. You can make this a little simpler by maybe making a $basepath variable so you don't have to keep typing the same paths over and over.


Your other problems is you have error messages to the user that show up before you print the HTML headers (Username check for sure). I would suggest printer your headers at the top of the page so you don't have to worry about this.

Opinion!!!:
You might want to also look into better password protection schemes. Storing flat text passwords in a directory that looks easily readable from the web looks very dangerous. If you are going to do it that way I would at least change where you are storing this information into a different directory than where you you HTML docs are.
 
Right, I was thinking about doing an .htaccess login system. Do you think that would be good?

This login system is just so I can test the rest of my site out anyways, so don't worry. ^_^

_______________________________________

You don't know me.
 
Another minor detail I noticed:

Code:
      print "That username allready exist, click back and try a different one\n";

This line is way above the line that prints the Content-Type. If the condition was true and that print was executed, it would print that out before having printed out proper HTTP headers.

This is one case in which its often a better idea to print the headers out near the very top of your script, so that things like this can be printed just fine without problem.

-------------
Cuvou.com | The NEW Kirsle.net
 
I have never used htaccess but have done sessions id/cookies.. which I found to be slightly hard. Someone who has done htaccess might have more info, but I heard it does a pretty good job.
 
Code:
Could not open dir [COLOR=red]portals[/color]: No such file or directory at e:\0\74\38\237038\user\240783\htdocs\mywebs\ETbyrne\[COLOR=red]portal[/color]\regester.pl line 25.
Looks like a typo perhaps.

Your flat file system will be fine if you host it outside your webroot, and it's still available to the web server user. When you get around to it, Sessions and a database are the way to go

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks for the heads up Kirsle.

I have never used htaccess but have done sessions id/cookies.. which I found to be slightly hard. Someone who has done htaccess might have more info, but I heard it does a pretty good job.

I have a section in my book about .htaccess. It is a little bit hard to follow though...

Looks like a typo perhaps.

I checked to see if it was a typo before I posted here, so that wasn't the problem.

Your flat file system will be fine if you host it outside
your webroot, and it's still available to the web server user. When you get around to it, Sessions and a database are the way to go.

So you're saying is I put it in let's say ./home/random/dirs/$author/password.txt and my site is in ./home/other/dirs

would that be fine?

_______________________________________

You don't know me.
 
as long as it's not accessible under the webroot, but still accessible by the webuser (the logon that perl runs under)

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
I'm still getting that error. I've checked many times to make sure that the dir does exist.

I've tried a number of formats for finding the dir. Here they are.

Code:
chdir "portals";

chdir ">>./mywebs/ETbyrne/portal/portals";

chdir "[URL unfurl="true"]http://www.mywebsfree.com/ETbyrne/portal/portals";[/URL]

I've even re-made the dir portals with a .pl script just to make sure the permissions were'nt messed up.

Maybe I nead a new web host. Do you guys know of any free ones that have no adds and allow you to put .pl scripts anywhere?

_______________________________________

You don't know me.
 
chdir "mywebs/ETbyrne/portal/portals" or die "$!";


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Yeah.. I don't know why you are starting with ./ either.. you have no idea where the start of the path the webserver has.. you need to hard code the full path in or you are going to always have problems..

/opt/apache/mywebs
or
/var/apache/mywebs

or whatever
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top