Page 1 of 1

Coverting a Perl Console Script to a Web Script!

Posted: Tue Apr 15, 2003 11:19 am
by Nik
What else must i do in order to get this Perl file act as a cgi script??


use warnings;
use DBI;
use DBD::mysqlPP;
use CGI qw(:standard);

print header;
print start_html('A Simple Example');

$db = DBI->connect("DBI:mysqlPP:database=db_nik;host=localhost") or
$db = DBI->connect("DBI:mysqlPP:database=db_nik;host=nik.wvbuzz.com", "nik", "macgyver", {RaiseError => 1});

open(IN, "diary.txt"); @diary=<IN>; close(IN);
open(IN, "tainies.txt"); @tainies=<IN>; close(IN);

$xronos = localtime; $i=0;

$ip = $ENV{'REMOTE_ADDR'};
@numbers = split(/\./, $ip);
$ip_number = pack("C4", @numbers);
($host) = (gethostbyaddr($ip_number, 2))[0];

print "<body background=pics/anemos.jpg>";
print "<font size=5 color=Yellow>";

print "<center><font size=5 color=Cyan>- ?anaaaae?a Oaeie?i DivX by Nik! -<br>";
print "<center><font size=4 color=Pink>* AeU?eooc ?anaaaae?a a?iae 5 oaei?ao ia euooio 4 euro aiU cd *<br>";
print "<center><font size=4 color=Pink>* Aea ?anaaaae?ao Uiu oui 10 oaeie?i oi euooio aiU cd eaoaaa?iae ooa 3 euro *<br>";
print "<center><font size=4 color=Pink>* Aea o?ueea eae ?anaocn?oaeo uoii aoinU oeo oaei?ao ?anaeae? anUoa iio ooi nik0s\@mycosmos.gr *<br><br>";


print "<form action=check.php method=post>";
print "<table border=1 width=50% align=Center bordercolor=Yellow style='border-style: solid; border-width: 5' background=pics/blue.jpg>";
foreach (1 .. 5)
{
print "<tr>";
print "<td align=center> <font size=5 color=LightGreen> O?oeio $_ co oaei?ao </td>";
print "<td align=center> <select name=dvd1> foreach(@tainies) {<option> $_ </option> }</select></td>";
print "</tr>";
}
print "</table><br><br>";


print "<table border=1 width=40% align=Center bordercolor=Yellow style='border-style: solid; border-width: 5' background=pics/blue.jpg>";
print "<tr> <td align=center> <input type=submit name=kataxorisi value=EYeu ia ?anaaaa?eu aooYo oeo 5 oaei?ao> </td></tr>";
print "<tr> <td align=center> <input type=submit name=emfanisi value=EYeu ia a? ?ieao oaei?ao Y?u ?anaaaa?eae> </td></tr>";
print "<tr> <td align=center> <input type=submit name=diagrafi value=EYeu ia iaoaaUeeu iea ?anaaaae?a ?io Y?u eUiae> </td></tr>";
print "</table>";
print "</form><br>";


print "<form action=eggrafi.php method=post>";
print "<input type=submit name=eggrafi value=Aaanao? IYeioo>";
print "</form>";

print "<form action=progs.php method=post>";
print "<input type=submit name=progs value=AeUoina ?ae?i?aea eae ?nianUiiaoa>";
print "</form>";

print "<form action=logos.php method=post>";
print "<input type=submit name=logos value=EaoiUoea ?iaoiaoeeU eae Oo?uoaeYooaoa Ea?iaia!>";
print "</form><br>";

print "<center><font size=4 color=Cyan>";

print "<table border=1 width=80% align=Center bordercolor=Yellow style='border-style: solid; border-width: 5' background=pics/blue.jpg>";
print "<tr>";
print "<td> <center><font size=4 color=Cyan> 1 </td>";
print "</tr>";
print "</table><br>";


@diary=();
open(IN, "diary.txt");

while (<IN>)
{
chomp;
next unless $_=~/\w/;
push (@diary, $_);
}

close(IN);

$len=$#diary;
$quote = int( rand(1 + $len) );
$quote-- if $quote == 1 + $len;
$quote = $diary[$quote];


print "<center><font size=4 color=Orange> $xronos";
print "<center><font size=4 color=Pink> $host";

$sql = "UPDATE counter SET visitor=visitor+1";
$db->do($sql);

$st = $db->prepare( q{SELECT visitor FROM counter});
$st->execute();

@visitor = $st->fetchrow_array();

print "<center><font size=5 color=Yellow> $visitor[0]";
print "<center><a href=personal><img src=pics/cross.gif></a>";

mail ("nik0s\@mycosmos.gr", "A??oeaoc Ao?Yioao $host => $visitor[0]", "", "From: 007\@spy.gr");

Thanks

Posted: Tue Apr 15, 2003 1:01 pm
by daven
1. At the top of the file, put this: #! /path/to/perl/executable
2. Have a cgi-bin directory on your webserver
3. make sure that you CHMOD the file so that it can be executed.

I have not looked over the code itself yet, due to being at work and not having much free time. But the above steps will permit a perl file to be executed as a cgi-script

Posted: Tue Apr 15, 2003 4:57 pm
by Nik
well i did put them bu i still get this error:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, nik@mycosmos.gr and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


--------------------------------------------------------------------------------

Apache/2.0.44 (Win32) mod_perl/1.99_08 Perl/v5.8.0 Server at dell Port 80

Posted: Tue Apr 15, 2003 7:37 pm
by volka
Did you try a simple "hello world" script to test your mod_perl installation?
And maybe when you're done with that you're interested in http://perl.apache.org/docs/tutorials/t ... _beautiful

Posted: Wed Apr 16, 2003 3:57 am
by Nik
I was missing the #!perl which it diddnt seem to work without it!!

now am getting somewhere??

But why i dont fet mail notification on replys??