homepage Welcome to WebmasterWorld Guest from 54.226.213.228
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Creating cgi script 500 error
creating cgi script with cgi
webgo2




msg:445125
 4:18 am on Mar 26, 2006 (gmt 0)

I'm attempting to create a cgi script with another cgi script, but I get a 500 error.

Here is the script:

mkdir("$main_dir/$mklinkid", 0755) die "Cannot make new dir: $!";

open(THISFILE, ">>$main_dir/$mklinkid/index.cgi");

print THISFILE qq~
#!/usr/bin/perl

require "/home/aaaaa/data/db.pm";
require "/home/aaaaa/public_html/control/control.pm";

use CGI::Carp qw(fatalsToBrowser);

\$linkIN = "$mklinkid";

\&opendb;
\$lo = \$dbh->prepare("select goto from links where link_id=\$linkIN");
\$lo->execute();
\$qw = \$lo->fetchrow_hashref();
\$gotois = \$qw->{'goto'};

\$dbh->do("update links set reset_hits=reset_hits+1, hits_total=hits_total+1 where link_id=\$linkIN");
\&closedb;

print "Location: \$gotois\\n\\n";
exit; ~;
close(THISFILE);

chmod(0755, "$main_dir/$mklinkid/index.cgi") die "Cannot chmod index file: $!";

The file created & permissions are changed just fine. The problem is that I get a 500 error when I run the created script. If I delete the created index.cgi from the created directory & create one manually with the same coding, it works.

Hopefully I have specified enough for someone to help me out. . . been working on it for almost 2 hours & can't figure it out.

Thanks.

 

DrDoc




msg:445126
 4:24 am on Mar 26, 2006 (gmt 0)

Welcome to WebmasterWorld! [WebmasterWorld.com]

Have you looked at the created file to verify that it does, indeed, have all the correct code? And, most importantly, what does your error log give as the error when your file is run?

webgo2




msg:445127
 4:31 am on Mar 26, 2006 (gmt 0)

Hi,
Yes, the code is the same. When I deleted the script created file, I copied the contents into the manually created file.

As far as the error log - It states "Premature end of script headers:" - which I didn't look at before.

Also - I am using cpanel. When I create a cgi script normally the file type is listed as:
"a /usr/bin/perl script text executable". On these script created files they are listed as "ASCII text". I think that may make a difference (cuz the file is being read as a text file?), but I can't be sure.

DrDoc




msg:445128
 5:21 am on Mar 26, 2006 (gmt 0)

[httpd.apache.org...]

That should give a few valuable clues ;)

DrDoc




msg:445129
 5:28 am on Mar 26, 2006 (gmt 0)

May I also, perhaps, suggest that you take a look here [webmasterworld.com]

perl_diver




msg:445130
 6:05 am on Mar 26, 2006 (gmt 0)

How are you calling this script from the other cgi script? And why don't you just include it in the main cgi script as a sub routine instead of making it a seperate script you call from the main cgi script?

webgo2




msg:445131
 6:11 am on Mar 26, 2006 (gmt 0)

Well. . .

I looked over the apache docs, I tried:

print "content-type: text/html\n";
&
print "content-type: text/html\n\n";

under the $linkID = "$mklinkid";

but still the same error.

I see this code on the apache site:

{
local ($oldbar) = $;
$cfh = select (STDOUT);
$ = 1;
#
# print your HTTP headers here
#
$ = $oldbar;
select ($cfh);
}

but I don't have a clue what to do with it. I realize the apache site states putting it aroud the print or write statement. . . but where? I am not a trained coder by any means, and I learn by doing searches & figuring it out from there - but I'm a little lost on this.

As per the second post, the servercheck.cgi - I get asked to login & then it redirects me to my control panel when I click on the link. . . what is it supposed to do?

Also, as I stated before - the newly created files are stated to be ASCII text, while my scripts that work are a /usr/bin/perl executable. To explain this better I have a screenshot:

I don't know if this has anything to do with it - but I would assume it would.

Thanks.

[edited by: jatar_k at 6:00 pm (utc) on Mar. 26, 2006]
[edit reason] no urls thanks [/edit]

webgo2




msg:445132
 6:26 am on Mar 26, 2006 (gmt 0)

perl_diver -

The script is for creating tracking links for affiliate sites. Instead of http://example.com/?1234 I am shooting for http://example.com/1234/ - so that it doesn't as much look like a tracking link.

I am not sure if I 100% understood what you were saying but the only one calling on the script would be someone clicking on the tracking link, then it'd track the details & redirect them to wherever.

But I'm not sure if I understood you properly.

perl_diver




msg:445133
 7:15 am on Mar 26, 2006 (gmt 0)

ahh, I was the one that misunderstood. If this is your entire script:


mkdir("$main_dir/$mklinkid", 0755) die "Cannot make new dir: $!";

open(THISFILE, ">>$main_dir/$mklinkid/index.cgi");

print THISFILE qq~
#!/usr/bin/perl

require "/home/aaaaa/data/db.pm";
require "/home/aaaaa/public_html/control/control.pm";

use CGI::Carp qw(fatalsToBrowser);

\$linkIN = "$mklinkid";

\&opendb;
\$lo = \$dbh->prepare("select goto from links where link_id=\$linkIN");
\$lo->execute();
\$qw = \$lo->fetchrow_hashref();
\$gotois = \$qw->{'goto'};

\$dbh->do("update links set reset_hits=reset_hits+1, hits_total=hits_total+1 where link_id=\$linkIN");
\&closedb;

print "Location: \$gotois\\n\\n";
exit; ~;
close(THISFILE);

chmod(0755, "$main_dir/$mklinkid/index.cgi") die "Cannot chmod index file: $!";

There is no shebang line at the beginning, ie: #!/usr/bin/perl

and these two variables have never been defined:

$main_dir/$mklinkid

so how can the script make the directory? Or is that not the whole script you posted?

perl_diver




msg:445134
 7:18 am on Mar 26, 2006 (gmt 0)

I assume you know these are two different things:

http://example.com/?1234
http://example.com/1234

the first one should maybe be:

http://example.com?1234

the second one is a sub directory of the web root so you would need to use some way of tracking the affiliate ID rather than using the query string like?1234 would.

webgo2




msg:445135
 7:44 am on Mar 26, 2006 (gmt 0)

Yes, sorry - I didn't post the entire script. . . it's kind of long. . . & I can't figure out how to make that border around the code to make it look nicer. . .

The $main_dir/$mklink is defined, just not posted:

$main_dir = "/home/aaaaa/public_html/folder";

$mklink is the last result in the links databse.

It might have been better to post the whole code earlier or a link to it cuz I think I'm causing confusion. I understand the difference between

http://example.com?1234 &
http://example.com/1234/

Inside my code I have this:

\$linkIN = "$mklinkid";

$linkIN is the "query string" in this situation.

I'll just post the whole page code to make it easier. . . it's near the top under 'Add link 2 db'

[edited by: jatar_k at 6:01 pm (utc) on Mar. 26, 2006]
[edit reason] no urls thanks [/edit]

perl_diver




msg:445136
 8:43 am on Mar 26, 2006 (gmt 0)

no syntax errors in the script you linked to, maybe one of the required scripts has an error in it somewhere.

webgo2




msg:445137
 4:20 pm on Mar 26, 2006 (gmt 0)

Well. . . the required scripts work, if there was an error I wouldn't be able to use any scripts that I required them from.

I'm begining to think this is a lost cause - I wrote my webhost last night & they state that it's always better to create scripts offline & upload them cuz there are "known bugs" in cpanel - I don't know what the bugs are, but if there are bugs & this is one of them it's not gonna work. . . I realize there are a multitude of ways to do just about anything using perl - but I don't know of another way to create a file other than what I've listed.

Thanks for your help & if you or someone else have any more suggestions please let me know.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved