Herself’s Webtools

Webtools for Webmasters: Scripts, HowTos, Templates, Plugins, Widgets, Tips and Useful Information

Herself’s Webtools header image 1

How to convert your old Perl-CGI scripts to work in your blog using PHP

June 23rd, 2008 · No Comments

The original TimesToCome site was created in 1997. The web has changed a great deal since then but my scripts hadn’t. I just hacked my blogs to use the PERL scripts. Converting them to work in your blog without using PERL or CGI is actually quite simple.

The first thing to do is convert your old CGI scripts to PHP. Your forms will remain the same except for the name of the script they are calling. ( <form method=”post” action=”new-script-url”> ) I found that User Friendly Forms in PHP, and PHP Form Handling gave me enough information to convert the forms from PERL to PHP. Most of what works in PERL, works in PHP, you’ll find very little needs to be changed. ( ‘PHP Black Book’ is the best book I’ve found so far. )

Once you have a working PHP form you need to incorporate it into your blog. To do this you need to create a page template. The easiest way is to copy an existing page template in your theme. The archives.php page usually works well.

Remove the archives information from the page. I deleted everything after <div id=”content” class=”pages”> down to the matching </div> tag for that division. Your template may be slightly different.

Now copy and paste your PHP form - everything between <body> and </body> into that space between <div id=”content” class=”pages”> and </div>.

Rename the page to something useful, and don’t forget to change the ‘Template Name: xxxx ‘ in the template.

Now log into your Wordpress or other blog. Create a new page, name it something useful. Then go to the templated drop down menu (’Templates’) and select your newly created template from the menu. Save and publish.

If you wish to use multiple pages for your form just create multiple pages. If you wish it to reload the same page when the script runs, call yourself in the action= and place a hidden check that lets you know if this page is being loaded or if the form is filled out and submitted.

Put the hidden check if form submitted in the form:

<input type=”hidden” name=”submit_check” value=”1″ />

The check for it in the part of the form you do your calculations:
if ($_POST['submit_check'] == 1 ) { /*do something*/ }

See example: Calorie calculator
Download example: Calories example php form in a WP blog

Tags: cgi · how to · perl · php

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

You must log in to post a comment.