Skip to main content
“CGI” stands for “Common Gateway Interface”. CGI is a popular method by which a web server can obtain data from (or send data to) databases, documents, and other programs, and present that data to viewers via the web. More simply, CGI is programming for the web. A CGI can be written in any programming language, but Perl is the most popular. System Requirements
  • PERL 5 or later for Windows.
  • A Microsoft Windows based Server running either Microsoft Personal Web Server (PWS) or Microsoft Internet Information Server (IIS).
  • TAL Barcode ActiveX Control (Plus version).
  • Microsoft Internet Explorer 4.01 or higher (recommended)
  • Microsoft Visual Basic 6.0 (To create and compile your own VB program)
While investigating how to create server side barcodes, we found that it is possible to use Perl CGI code to do the job however it was also determined that using Active Server Pages is far easier, quicker and requires less work to implement. Since we had developed a method of using a Perl CGI Script (with some help from a compiled Visual Basic program) to achieve the same results as our ASP page example, we have included here.

How it works

The user completes an HTML form with information about the barcode they wish to create, such as the symbology, the text to be encoded, the text for the comment, etc. and submits the information to the server. This information is decoded by the Perl script and passed to an executable program, written in Visual Basic. The VB program generates a barcode to the visitors’ specifications and saves it as an image file with a unique filename. The unique filename is based on a number, generated by the Perl script using a file called “Counter.txt”. Counter.txt contains nothing more than a number, which the Perl script reads into a variable called “$COUNT”. Count is then incremented and the text file updated. The script then passes the number to the VB program along with the form data. The VB program also generates some HTML that can be used to display the image the correct size in the visitors browser, and saves it to a text file. The Perl Script opens this text file and copies the HTML from it as it generates the page to display in the Browser.

Using this example

  1. Download, unzip and install Perl 5
  2. Configure your Web Server to run Perl Scripts
  3. Download the files discussed in the example below. This is a self extracting zip file containing the HTML form, Perl script, Visual Basic project files, the compiled program for those of you who do not have Visual Basic, but would still like to test it, and the “counter” file.
  4. Extract the files. Copy “Getbarcode.exe”,”Barcode.pl” and “counter.txt” into your “Scripts” folder (usually “C:\Webshare\Scripts”).
  5. Copy “perlForm.htm” into the root directory of your web site (usually C:\Webshare\Wwwroot).
  6. Open your Web browser and type in “http:// your.Server.name/perlForm.htm” into the address line, change the properties that interest you on the form, and submit it. You should be rewarded with a barcode. If you are not, check out the troubleshooting section at the end of this document.
  7. If you have Visual Basic 6 you can open the VB project and make changes to the “Getbarcode” program and recompile it. (If you have an older version of Visual Basic you may not be able to open the project but can still import the form and the module, or copy and paste the code from this page into your own project).

Sample HTML form code

See here for the sample code for building an HTML Form.

Sample perl script

# Tell the server that this is a Perl Script, and where to find the Perl interpreter.

Sample visual basic code

Module 1 Code This is the code that generates the barcodes. The parameters specified by the user are passed by the Perl Script to this routine as one long string of data separated by the tilde (~) character. The routine below parses out the parameters into an array of data, then sets the properties of the activeX control with the data supplied by the user. The properties are matched to the data based on the order in which they were received. The barcode is then saved as an image file using the SaveBarCode Method. The image is saved in a format appropriate for the user’s Browser (PNG is preferable because its compression technique generates smaller images than GIF files, meaning that the page will load faster and less space is required on the server). The HTML code required to display the image is written to a text file with the same name as the image, which the perl script opens up and uses to display the final image on the page. Note: In the code below there is no data validation to verify that submitted data is appropriate for the symbology selected, nor does it check to see if all required information was supplied. If you plan to use this technique such additional checking will be required.
Form Code If no command line arguments are passed to the program the following form appears. It can be used by the administrator to set the Default settings on the Server. If command line arguments are passed to the form, then the form will not be displayed. Server-Side Barcodes Configuration Editor form with barcode message, symbology, color, and file path settings This is the code behind the Visual Basic Main Form: Private Sub chkBearer_Click()

Troubleshooting

How do i find out what the homepage or root directory of my Web server is?

If you do not know your Server name or the root directory of your web server, then double click on the Web Server icon in your system tray to find out: Personal Web Manager window with the PWS system tray icon and home directory path circled If you are running an older version of PWS or FrontPage Web Server, then your icon and PWS manager may look like this: Personal Web Server Properties dialog for an older PWS version, with the Default Home Page field circled The most likely causes of this problem are:
  1. Check that the line of code that saves the barcode is saving it to the same folder that the tag expects to find it in. For example, in our code above we are saving the image into the root directory of the website. If we were to set the “src” (source) attribute to our image tag incorrectly (such as having it look in the scripts folder) we would get a broken link since the image is not going to be in that folder.
  2. Verify that the image is being created in the specified folder. If the image is not being created then it may be a permissions issue. Check that the public has write access to the folder in which you wish to save the barcodes.
  3. You tried to create a barcode with invalid parameters.

When i submit the form i receive “cannot find server”

Verify that you have started the Web Server by double clicking on the icon in the system tray if a button marked “Start” is available then click on it to start the Web Server If the button says “Stop” then try stopping and restarting the Web Server. If this does not resolve the problem make sure that you opened the form via http, rather than as a file on your hard drive. In other words, the address line in your Browser should read: “http://your.Server.Name/perlForm.htm” not “C:\WEBSHARE\WWWROOT\perlForm.htm”.

When i submit the form i receive “http 404 not found”

This error means that the script (or the form) is in the wrong folder. For example, you may have copied both the form and the script into your “Scripts” folder (C:\WEBSHARE\Scripts). Since your Web Server’s name is different to ours we used a relative link when telling the form where the barcode.asp script is located. When you submit the form, it tells the Web Server that the script is one level deeper than the form on the server, inside a folder called “Scripts”. If the form is already inside that folder, then the Server is looking for C:\WEBSHARE\Scripts\Scripts. Since this folder probably does not exist it cannot find the script it is looking for. To resolve the problem, either move the form to the C:\WEBSHARE\WWWRoot folder, or change the tag in the html form to point to where the Script actually is. In this example, changing the line to read would resolve the problem.

When i submit the form i receive “http error 403 403.1 forbidden”

This error indicates that the folder into which you copied the barcode.pl and “Getbarcode.exe” file does not have execute permissions. Either move the files to a folder that does have execute permissions such as the “Scripts” Folder, or grant execute permissions to that folder. To grant execute permissions, open the Personal Web Server Manager, click on “Advanced”, double click on the folder you wish to use, then check the “Execute” and “Scripts” checkboxes and click “OK”. (On older versions of Personal Web Server click on “Administration”, and then change the properties of the folder).

When i submit the form i receive “http error 405 – method not allowed”

This error means that your server is not configured to run Perl scripts. Configure your server to run Perl Scripts. If restarting the server doesn’t work then reboot the server machine.

When i submit the form i receive “error 500 – internal server error”

This means that there is a syntax error in your Perl script. The best way to find it is to open an MSDOS window, navigate to the directory where you installed Perl and type: Perl -c script.pl (where “script.pl” is the name of your script. Note: If you script is in a different folder to the Perl interpreter – which for the sake of security it certainly should be! – then you must specify the full path to the script: e.g. Perl -c C:\webshare\wwwroot\CGI-bin\script.pl). The “-c” argument tells Perl to compile the script without actually executing it. If there is a compilation error Perl will inform you which line the error is on and often why the error occurred. Common syntax errors that cause an Error 500 include:
  • “Missing semicolon in previous line.”
  • “Can’t find terminator before EOF.” This message is usually the result of a missing right bracket or quotation mark.
  • “Might be a runaway multi-line string starting on line n.” This is usually a missing quotation mark.
  • “Missing right bracket”
By using Perl to compile your script you can turn a very baffling Error 500 into a simple “whoops I seem to have forgotten to close my quotations on line 10”. It is also extremely important to remember that Perl is case sensitive. If you create a variable called testandthenlaterrefertoitastest and then later refer to it as Test you will get unexpected results since $Test is considered by Perl to be a new and empty variable. For example:
Clearly, when the code was written I expected to print 6 + 2 = 8 onto my web page, but what I actually get is 6 + 2 = 2. While in this case we would not get a Server error, we would not get the result we expected and would be left looking rather silly.

When i submit the form i see the perl script as a text document

This means that your server is not configured to run Perl scripts. Configure your server to run Perl Scripts. If restarting the server doesn’t work then reboot the server machine.

When i try to run the getbarcode.exe program it generates an “automation error” or something about a missing DLL file?

To resolve the problem, the latest Visual Basic Runtime files must be installed onto the client machine before the program can run successfully. Where Do I Get these files? The VBRUN60.EXE file is available for download here. Reference : For additional information, please see the following article in the Microsoft Knowledge Base: ARTICLE-ID : Q192461 TITLE : FILE: VBRUN60.EXE Installs Visual Basic 6.0 Run-Time Files In our Example, we did not include any code to validate the data. Some Barcode symbologies have very strict rules about what can be encoded, UPC-A for instance, can only accept a 12 digit numeric message. If you type in “Test” and select UPC-A then the ActiveX control produces an error and sets the size properties back to the defaults for code 39 encoded with 1234567890, but it does not save a barcode to disk. You will recall that we allowed for 10 unique barcodes to be generated before it rolls over and starts overwriting. If you haven’t yet created 10 barcodes then you will probably get a broken link, otherwise you will get a distorted image of the last number n barcode. To prevent this from happening you should write some code to do some basic data validation before and/or after the form data is submitted using javascript, Perl and/or VB code. You should also create a page or message that appears to inform the user that they entered invalid parameters. Examples of these techniques will be made available soon.
Last modified on November 3, 2026