Running a CGI script in my browser WAMP - html

I am trying to run the basic cgi script to generate some html and I am just getting the raw code, here is the general script. Is there something else I have to set, I am on a windows system.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print <<HTML;
<html>
<head>
<title>A Simple Perl CGI</title>
</head>
<body>
<h1>A Simple Perl CGI</h1>
<p>Hello World</p>
</body>
HTML
exit;

You should follow the tutorial here: http://chromicdesign.com/2009/05/setting-up-perl-for-wampp.html
Hopefully you'll be up and running in the end.
Cheers,

Related

phpinfo() Expression Web 4

I've installed Microsoft Expression Web 4, installed php 5.3.28, renamed the php.ini-production to php.ini, did display_errors=on, did cgi.force_redirect=0, switched the positions of php_mbstring.dll and php_exif.dll (ran php.exe and it said it could not find php_mbstring.dll), directed expression web to the php-cgi.exe, and forced expression web 4 to boot a server for every test. I run the sample code for php information as follows...
file name - "index.php"
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled 1</title>
</head>
<body>
<?php
phpinfo() ;
?>
</body>
</html>
I get a blank page (WSOD), and am still looking for a solution.
In short I've been following the instructions given here.
And followed up with some additional potential fixes with little success.
Thank you in advance for your time.
Solved the problem, did a full reinstall of all products involved.

Perl script wont run; just displays actual code in the browser

I am new to Perl and am having trouble getting my scripts to run properly. Where am I supposed to put the actual Perl scripts in order for them to run correctly? I am testing everything out on my lap top and am trying to call a script from a html page and all I get is the actual script (code) itself displayed in my web browser as opposed to the information that the code is designed to produce. Therefore, I figure I am supposed to put the Perl file somewhere else? Currently I have the Perl script and the HTML file in the same directory. Any help would be greatly appreciated! See below:
<head>
<title>Student Web Page</title>
</head>
<body>
<h1>WELCOME! You have reached Kito's Student Web Page</h1>
<br />
<p>To run the folloiwing applications, click on the appropriate line:</p>
<form ACTION="first.pl" METHOD="get">
<p>
<input TYPE="submit" VALUE="Step 5 - Perl Environment Variables">
</p>
</form>
#!c:\perl\bin\perl.exe -w
use strict;
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Environment Variables</TITLE></HEAD><BODY>";
foreach (keys %ENV) {
print "<BR><FONT COLOR=green>$_</FONT> is set to <FONT COLOR=red>$ENV{$_}</FONT>";
}
print "</BODY></HTML>";
You need to configure your webserver to execute the CGI file. How this is done depends on the webserver and operating system.
Some examples:
http://www.thesitewizard.com/archive/addcgitoapache.shtml
Under linux with apache install the mod_cgi module. Under windows with IIS install activestate perl.

How can I call a Perl script inside HTML page?

I have a single HTML file, how I use a Perl script(date/hour) in the HTML code?
My goal: show a date/hour in HTML
Obs.: alone both script are ok.
Example:
HTML File:
<html>
<body>
code or foo.pl script
</body>
</html>
Perl script(foo.pl):
#!/usr/local/bin/perl
use CGI qw/:push -nph/;
$| = 1;
print multipart_init(-boundary=>'----here we go!');
for (0 .. 4) {
print multipart_start(-type=>'text/plain'),
"The current time is ",scalar(localtime),"\n";
if ($_ < 4) {
print multipart_end;
} else {
print multipart_final;
}
sleep 1;
}
Perl is a server-side language, so it must be run on the server. The HTML code is displayed in the browser, and it is generated by the server. So you would have to run the perl script on the server to generate the date / hour, and embed that into the HTML code that you serve to the browser.
Here is a tutorial on how to do this.
It sounds like you want Ajax. Your HTML page uses JavaScript to call your Perl program. Your JavaScript gets the response and replaces the part of the page where you want the data to go. Alternatively, you can just skip the Perl bit altogether and just do it all in JavaScript.
You can either generate the entire HTML page via a CGI script (as per Chetan's answer) - or as an alternative you can use one of the templating modules (EmbPerl, Mason, HTML::Template, or many others).
The templating solution is better for real software development, where separation of HTML and the Perl logic is more important. E.g. for EmbPerl, your code would look like:
<html>
<body>
[- my $date_hour= my_sub_printing_date_and_hour(); # Logic to generate -]
[+ $date_hour # print into HTML - could be combined with last statement +]
</body>
</html>

How to include Perl into shtml files

Hi I am trying to include a perl script within my shtml file. Unfortunately when I do my script doesnt seem to run but instead it just displays the content of the script.
The code I am using is as follows:
test.shtml:
<html>
<title> business home page </title>
<body>
</br>
<!--#echo var="DATE_LOCAL" -->
<br />
<!--#include virtual="hello.pl"-->
</body>
</html>
hello.pl:
#!C:/Sun/WebServer6.1/bin/https/perl/perl
print "Content-type:text/html\n\n";
print "Hello World!";
I am not sure what I am doing wrong. Incase you all wanted to know the server I am using is Sun One WebServer 6.1 (OS = Windows XP). Thanks for your responses!
The de facto standard SSI directive for executing dynamic content within an SSI page is
<!--#exec cgi="hello.pl"-->
That works with Apache mod_include and at least a few other web servers that support SSI. No idea if it will work on your platform, but give it a shot.
Try getting rid of the first print statement in your Perl program, which sets the content-type header. That's not a useful thing to do in the body of an HTML page, which is where your SSI is located.
SSI is a rather quaint technology these days, even if it is occasionally useful, so if you are serious about learning web programming then this is not an area where you should spend much time.

make my file readable as either Perl or HTML

In the spirit of the "Perl Preamble" where a script works properly whether executed by a shell script interpreter or the Perl interpreter...
I have a Perl script which contains an embedded HTML document (as a "heredoc"), i.e.:
#!/usr/bin/perl
... some Perl code ...
my $html = <<'END' ;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
... more HTML ...
</HTML>
END
... Perl code that processes $html ...
I would like to be able to work on the HTML that's inside the Perl script and check it out using a web browser, and only run the script when the HTML is the way I want. To accomplish this, I need the file to be openable both as an HTML file and as a Perl script.
I have tried various tricks with Perl comments and HTML comments but can't get it quite perfect. The file as a whole doesn't have to be "strictly legal" HTML (although the embedded document should be)... just displayable in a browser with no (or minimal) Perl garbage visible.
EDIT: Solved! See my own answer
Read it and weep Mr. #Axeman... I now present to you the empty set:
</dev/fd/0 eval 'exec perl -x -S $0 ${1+"$#"}' #> <!--
#!perl
... some Perl code ...
my $html = << '<!-- END' ; # -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
... more HTML ...
</HTML>
<!-- END
... Perl code that processes $html ...
# -->
This sounds like a path to pain. Consider storing the HTML in a separate file and reading it in within the script.
Maybe this is a job for Markup::Perl:
# don't write this...
print "Content-type: text/html;\n\n";
print "<html>\n<body>\n";
print "<p>\nYour \"lucky number\" is\n";
print "<i>", int rand 10, "</i>\n</p>\n";
print "</body>\n</html>\n";
# write this instead...
use Markup::Perl;
<html><body><p>
Your "lucky number" is
<i><perl> print int rand 10 </perl></i>
</p></body></html>
You could also drop the use Markup::Perl line and run your script like
perl -MMarkup::Perl my_page_with_embedded_perl.html
Then the page should render pretty well.
Sounds to me like you want a templating solution, such as Template::Toolkit or HTML::Template. Embedding HTML in your code or embedding code in your HTML is a recipe for pain.
Have you considered putting Perl inside of HTML?
Like ASP4 does?
It's a lot easier that way - trust me ;-)