Lets now switch our attention back to creating perl aware web pages
Exercise 3
You are going to create an html page that runs a perl script on a server as a cgi program.
You will create 2 files - an html file to call the perl script and the perl(cgi) script itself.
Smile, this is supposed to be fun !
1. The Cgi file
Create a text file with the following content
#!/usr/bin/perl print "Content-type: text/html","\n\n"; print "Hello your name\n";
Save the file as script1.pl in your cgi-bin directory
- the first line of the script tells unix where to find perl.
- the second is the response header that is part of every cgi program.
- the third line displays a text message, duh!
Change the file permissions so it can be read and executable by the world.
Note: One of the main sources of problems in this work is setting the file permissions correctly.
2. The WebPage
Create a text file with the following
<body> <h2>My first Cgi Script</h2> <a href='cgi-bin/script1.pl'>Click here to execute the script</a> </body>
Save the file as script1.html in your public_html directory.
Run Internet Explorer and load the page script1.html, then click on the
link.
You should be shown a page with 'Hello yourname' on it.
If it worked, Congratulations you just wrote your first CGI program.
Most of the errors you will make in this course will relate to incorrect permissions on files or putting files in the wrong directories.
If your script doesn't work, try