Perl CGI Redirect Primer Tutorial

Perl CGI Redirect Primer Tutorial

Perl CGI Redirect Primer Tutorial

Today we venture into the world of CGI (Common Gateway Interface) on our Apache/PHP/MySql web server. So what language is default for CGI work on such a web server? It could be Perl or Python, or maybe something else like Peas, Poodles or Pomegranates, though the last three should be likely, but, alas, are not probable. On our CentOS web server the default CGI is Perl.

Care is needed with CGI work, as you are opening up a program that can get to your Operating System to access from public Internet places. So in the code you’ll see below there is a check for where the user came from, as to whether the access should be allowed or not to the real thrust of what the Perl CGI does, and that is to redirect you to a Google Translate page (thanks) that takes the language picked by the user and welcomes you to the tutorial.

Perl CGI (or any CGI) should be given the proper stringent permissions, and any advice given by your hoster may need to be adhered to. With this, as with all Perl things, like Perl and CGI for the World Wide Web by Elizabeth Castro … ta muchly.

The Perl actually does a <meta … > type of redirect available to all (ie. mere mortal plus CGI-less-(or-is-that-more?)-mere mortal) HTML up in its header. This technique can be good to handle the same functionality at multiple places on a Unix/Linux web server (where uppercase/lowercase matters) regarding guesses by the user as to URLs (eg. if you expect users to try typing in the URLs themselves and there is just as much likelihood they’ll type “Applescript” as “AppleScript” then you could have an AppleScript directory that only contains index.html which virtually only contains a <meta … > tag type of redirect to the Applescript directory where the real logic resides).

Have a feeling that such redirects annoy the search engines, and this may be an overriding consideration for you, regarding this.

You may ask … can’t all this be done in Javascript? Mostly, yes, but Javascript can’t get you the server time without a lot of trouble.

So, yes, CGI is that powerful interface to the server … server side logic … so write code to use it when Javascript (in its usual client-side guise) cannot help you.

Typically CGI is often accessed in the action part of an HTML form tag definition, as for our (live) tutorial today.

Will leave you with some downloadable programming Perl source code you could call language.cgi supervised by some HTML code containing the calling form called picklanguage.html

If this was interesting you may be interested in this too.

This entry was posted in eLearning, Software, Tutorials and tagged , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *