Added for You
#1 in Business Subscribe Email Print

You are here: Home > Internet and Businesses Online > Web Development > Running a CGI Script on a Web Server

Tags

  • every
  • articlelocalscriptplname
  • directory
  • local versionhere
  • server version
  • serverthe script

  • Links

  • Botticelli: From the Birth of Venus to a Bonfire of the Vanities
  • Home Improvement Tips for Selling Your Home: Mortgage Advice
  • Ten Tips for Spring Cleaning
  • Added for You - Running a CGI Script on a Web Server

    Top 10 Strategies for Making Your Website Visible in Search Engines
    Within each strategy listed here, there are components to be handled and completed. Knowing the strategy is the first step.Here are 10 elements to have in place on your website so you will be found when your target audience looks for you in a search engine.1. Define your keywords. Brainstorm every possible word someone might type into a search engine if they didn’t know of any website on the topic of their interest. Imagine yourself as new to your topic, not knowing the main words that apply.2. Do your keyword research. Find out how many people search for every single one of the words you came up with every single day. Choose the ones you want
    ial points to note:

    1. Why does the script have a .cgi extension instead of a .pl extension? CGI is an abbreviation for Common Gateway Interface, which is a specification for transferring information between a web server and a CGI script. So CGI iteself is not a language, but CGI scripts can be written in a number of languages of which Perl is one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server.

    2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally.

    Ok, lets go through the script line by line to see what's going on.

    Running the script

    To run the script y

    A New Twist On An Old Friend - The Chronological Resume
    What is a chronological resume? A chronological resume is a resume in which you list your past jobs and educational qualifications in reverse chronological order, beginning from the latest or the present one first. This is the traditional and most well known resume format.Why Use A Chronological Resume?A chronological resume is especially effective for mid-career professionals and new grads that have limited work experience. It allows the employer to see all of your qualifications including education upfront. Your resume shouldn’t read like a Ph.D. Dissertation – it should get straight to the point, and the chronological resume does this and m
    For many years I have been writing Perl scripts to process ASCII files of one sort or another on my computer. I typically do this when I need to reformat or tidy up a series of HTML pages, for example.

    To run a Perl script that is installed on your computer, which needs to process one or more files on your computer, and where the Perl interpreter is also installed on your computer, is very simple - you just need to double-click the perl script and it does the business - assuming that everything is set up correctly of course, for example, the location of the perl.exe program is defined in your path. You can also open a DOS window and type perl perlfile.pl to run a script (where perlfile.pl is the name of the Perl script you want to run).

    However, when it comes to running a Perl script, or CGI script, on a web server, things can be a bit trickier - not too tricky, but a bit trickier.

    In this article I'll look at two versions of the same script: one that will run quite happily on a local machine (by double-clicking the script, for example), and one that will run on a web server.

    The script itself is very simple - it opens a file, changes some text inside the file, and then saves the file under a different name.

    Version 1 - the local version

    Here is version 1 of the script. This is the version that will run locally on a computer, without a web server is sight. Note that I've inserted spaces at appropriate places to prevent the code from being processed by your browser. I've done this wherever necessary in this article.

    localScript.pl

    $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    This script opens a file called before.htm, uses a regular expression to change the string 'hello world' to 'goodbye cruel world', and writes the contents to a file called after.htm. If after.htm does not exist, it is created.

    The file before.htm simply contains one line - hello world. So it's not even a proper HTML file in fact, but that doesn't matter for this exercise as it's the script that's important, not the file that's being processed.

    Version 2 - the web server version

    Here's the web server version of the script. It contains everything that's in version 1, plus a bit more. Again, I've inserted spaces where appropriate to ensure that the code displays correctly in your browser.

    webScript.cgi

    #!/usr/bin/perl -w
    use CGI qw(:all);
    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
    warningsToBrowser(1);
    use strict;
    print header;
    my $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    my $line;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    A couple of initial points to note:

    1. Why does the script have a .cgi extension instead of a .pl extension? CGI is an abbreviation for Common Gateway Interface, which is a specification for transferring information between a web server and a CGI script. So CGI iteself is not a language, but CGI scripts can be written in a number of languages of which Perl is one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server.

    2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally.

    Ok, lets go through the script line by line to see what's going on.

    Running the script

    To run the script yo

    Customer Follow Up Strategies - 3 Powerful Techniques to Build Your Empire
    Here's a fact: The difference between highly successful businesses on the Internet is in the important factor of customer follow up.Because it's been proven that it's many times easier to sell to your existing customers again and again, instead of going out there and finding new prospects and trying to convince them to buy from you for the first time.So let me ask you a question: After you have spent a lot of money and energy to finally gain a prospect's trust and get them to order your product, what do YOU do?Do you forget about them and go for getting new prospects and continue trying hard to sell to them?If you do thi
    too tricky, but a bit trickier.

    In this article I'll look at two versions of the same script: one that will run quite happily on a local machine (by double-clicking the script, for example), and one that will run on a web server.

    The script itself is very simple - it opens a file, changes some text inside the file, and then saves the file under a different name.

    Version 1 - the local version

    Here is version 1 of the script. This is the version that will run locally on a computer, without a web server is sight. Note that I've inserted spaces at appropriate places to prevent the code from being processed by your browser. I've done this wherever necessary in this article.

    localScript.pl

    $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    This script opens a file called before.htm, uses a regular expression to change the string 'hello world' to 'goodbye cruel world', and writes the contents to a file called after.htm. If after.htm does not exist, it is created.

    The file before.htm simply contains one line - hello world. So it's not even a proper HTML file in fact, but that doesn't matter for this exercise as it's the script that's important, not the file that's being processed.

    Version 2 - the web server version

    Here's the web server version of the script. It contains everything that's in version 1, plus a bit more. Again, I've inserted spaces where appropriate to ensure that the code displays correctly in your browser.

    webScript.cgi

    #!/usr/bin/perl -w
    use CGI qw(:all);
    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
    warningsToBrowser(1);
    use strict;
    print header;
    my $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    my $line;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    A couple of initial points to note:

    1. Why does the script have a .cgi extension instead of a .pl extension? CGI is an abbreviation for Common Gateway Interface, which is a specification for transferring information between a web server and a CGI script. So CGI iteself is not a language, but CGI scripts can be written in a number of languages of which Perl is one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server.

    2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally.

    Ok, lets go through the script line by line to see what's going on.

    Running the script

    To run the script y

    Negotiation in Online Sales - You Got to Be Kidding?
    Ever heard of this? Negotiating in Online sales. Why would you have to, aren't all the offers fixed anyway. If all the offers were fixed why do they send you different packages or different emails. How valuable is your time? It all depends on who you are dealing with and what you are looking for doesn't it.If you are looking for a specific piece of information,that you require to help develop or expand the model or stage you are at, then where do you go to get that information? Well the traditional person would go to Google.com and do a "search". But what else is out there? Where are the caveats for finding certain types of information? Well what are you loo
    k") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    This script opens a file called before.htm, uses a regular expression to change the string 'hello world' to 'goodbye cruel world', and writes the contents to a file called after.htm. If after.htm does not exist, it is created.

    The file before.htm simply contains one line - hello world. So it's not even a proper HTML file in fact, but that doesn't matter for this exercise as it's the script that's important, not the file that's being processed.

    Version 2 - the web server version

    Here's the web server version of the script. It contains everything that's in version 1, plus a bit more. Again, I've inserted spaces where appropriate to ensure that the code displays correctly in your browser.

    webScript.cgi

    #!/usr/bin/perl -w
    use CGI qw(:all);
    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
    warningsToBrowser(1);
    use strict;
    print header;
    my $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    my $line;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    A couple of initial points to note:

    1. Why does the script have a .cgi extension instead of a .pl extension? CGI is an abbreviation for Common Gateway Interface, which is a specification for transferring information between a web server and a CGI script. So CGI iteself is not a language, but CGI scripts can be written in a number of languages of which Perl is one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server.

    2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally.

    Ok, lets go through the script line by line to see what's going on.

    Running the script

    To run the script y

    Wholesale Drop Shippers: What To Look For - What To Lookout For
    True drop shipping is defined by only three (3) players.1- The CONSUMER who is the final purchaser of the product. 2- The RETAILER who markets, advertises and accepts payment for the product from the consumer. 3- The DROP SHIPPER who ships the product for the retailer to the consumer.Let's look at each player. We will assume that we all know the consumer but retailers take many forms. Some are brick and mortar stores or catalog companies and others are internet based.Retailers bear the expense, time and creativity to show, market, advertise, price, sell and collect payment for a product. Upon selling and collecting payment for an item, the reta
    t. It contains everything that's in version 1, plus a bit more. Again, I've inserted spaces where appropriate to ensure that the code displays correctly in your browser.

    webScript.cgi

    #!/usr/bin/perl -w
    use CGI qw(:all);
    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
    warningsToBrowser(1);
    use strict;
    print header;
    my $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    my $line;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    A couple of initial points to note:

    1. Why does the script have a .cgi extension instead of a .pl extension? CGI is an abbreviation for Common Gateway Interface, which is a specification for transferring information between a web server and a CGI script. So CGI iteself is not a language, but CGI scripts can be written in a number of languages of which Perl is one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server.

    2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally.

    Ok, lets go through the script line by line to see what's going on.

    Running the script

    To run the script y

    Wife's Marketing Prowess Helped Edison See the Light
    It is well known that Thomas Edison was an inventor, a genius, and he never slept. Did you know that Mrs. Edison was a genius and never slept too? She was the marketing guru behind his engineering success. True, Tom had discovered what is today known as the light bulb. When he showed it to the Mrs. Mina Edison, his second wife, she asked “what are you going to call it?”Tom said. “I call it an affordable electrical home-lighting device.”“Great,” she responded, “with a name like that it will sit on the shelf at the patent office. We will just add it to the other money-losing patents you have conceived.”“How will people know what it does? She ask
    ial points to note:

    1. Why does the script have a .cgi extension instead of a .pl extension? CGI is an abbreviation for Common Gateway Interface, which is a specification for transferring information between a web server and a CGI script. So CGI iteself is not a language, but CGI scripts can be written in a number of languages of which Perl is one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server.

    2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally.

    Ok, lets go through the script line by line to see what's going on.

    Running the script

    To run the script you need to first upload the script and the file before.htm into the cgi-bin directory on your web server. On your web server the cgi-bin directory might be called something else, but it will probably be recognizable as the place where cgi scripts need to be located.

    By default, when you upload a file onto your web server it will probably have permissions of 644. You need to change these to 755 so that the script can be run by anyone. Your ISP should provide you with a way to do this. If not, contact me at john@dixondevelopment.co.uk and I'll send you a script to change the permissions for you.

    Once you have uploaded the files and changed the permissions, all you need to do is browse to the script in your favorite browser. If the browser window is blank, then everything has probably worked OK. Check in your cgi-bin directory to see if the file after.htm has been created and that it contains the words 'goodbye cruel world'.

    HTTP = HTML link (for blogs, profiles,phorums):
    <a href="http://www.added4u.com/article/86350/added4u-Running-a-CGI-Script-on-a-Web-Server.html">Running a CGI Script on a Web Server</a>

    BB link (for phorums):
    [url=http://www.added4u.com/article/86350/added4u-Running-a-CGI-Script-on-a-Web-Server.html]Running a CGI Script on a Web Server[/url]

    Related Articles:

    10 Reasons I Love Marketing

    Office Chairs for Big and Tall People.

    5 Tips for Developing a Website for Your Audience

    Bookmark it: del.icio.us digg.com reddit.com netvouz.com google.com yahoo.com technorati.com furl.net bloglines.com socialdust.com ma.gnolia.com newsvine.com slashdot.org simpy.com shadows.com blinklist.com