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.
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?
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.
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]
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.
mkdir("$main_dir/$mklinkid", 0755) ¦¦ die "Cannot make new dir: $!";open(THISFILE, ">>$main_dir/$mklinkid/index.cgi");
print THISFILE qq~
#!/usr/bin/perlrequire "/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?
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.
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]
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.