The Variables Page 4

Now that you know you can upload a script and execute it successfully, it is time to make some more changes to the script so we can increase its functionality. Let’s open the program in the text editor and move onto the next few lines:

######### This Section is where we will START to define all of our variables #########

# The name of our text file we are going to use
$FileName = "";

# The path (not the url!) to the directory where the text file is located
$ServerPath = "";

######### This is where we will END identifying our variables ####################

The first two and final lines of this block of code are comments. It is always a good idea when writing a program to include comments to help you better understand what you have written. The first new thing we encounter is a variable. The best way to think of a variable is as a place to store something. For right now, we are going to use scalar variables, or variables that can only hold one piece of information. The first variable we encounter, $FileName, will hold the name of our file where we wish to store our information. We can name our file whatever we want to. I chose to name it information.txt, but conceivably it could be named anything: sam.data, file.test, etc.. We edit our variable by inserting the information between the empty quotation marks. Our line would now look like this:

$FileName = "information.txt";

It is very important that you remember to terminate all of your lines with a semicolon. There are a few exceptions to this rule but it is best to operate under the notion that all simple expressions in Perl are terminated with a semicolon. The next scalar variable we need to modify is the $ServerPath variable, or the path to our text file. When working with Perl it is important to remember the difference between server paths and URLs. An URL would look like this http://www.somedomain.com, while a server path would look like this "/usr/www/web/". A server path differs in that it tells the server how to access the file as opposed to how the client or user would access the file. The variable must end with the appropriate Perl directory delimiter, "/" for Unix and Windows or ":" for the MacOS. You should again consult your ISP to determine the correct server path to your root directory. Let’s say for example that the correct server path to your root directory is "/usr/www/web/". If we wanted to access a folder in your root directory named info,we would notate the server path as "/usr/www/web/info/". As we configure the server path variable, you will need to decide where you want to place your text file. It can be in any directory on your server that you have access to. For this example, we will assume that you are placing it in a folder named info and that the correct server path would look like this:

$ServerPath = "/usr/www/web/info/";

The next thing we need to do is to create an empty file with the corresponding name you specified in the $FileName scalar variable. Once this has been completed you are ready to upload the program and file to the server. Make sure when you upload the file, information.txt--stored in our variable $FileName--that you upload it to the directory you specified in $ServerPath. After you have uploaded the file you will need to set its permissions to 777, chmod 777 information.txt. In some circumstances, you may also have to chmod the directory as well

Now that you have everything configured properly and uploaded to the server, it is time to test to see if you’ve made any mistakes. First let’s start out by just calling the script by itself (http://www.yourdomain.com/cgi-bin/script.cgi). If it says "you have been logged" on the screen then you have installed the script correctly. Now we need to call the script the way it was meant to be called, via a server side include. Generally all you need to do to use a server side include is to change the extension of the file from html or htm to shtml (somefile.htm becomes somfile.shtml). You then need to insert a call to your program within the html that would look like this:

This article was originally published on Aug 7, 1999

Thanks for your registration, follow us on our social networks to keep up-to-date