Make your own free website on Tripod.com

Personal info CV Services Scripts Search

Personal Info

About me, my sample sites and contact Information.

My Resume

Website Design
CGI scripts

Search my site

CGI scripts

Free scripts
Resources

>>Home



New updated scripts!!

I've added a new subcribe script to my site. This script is really simple. It gets the email entered in to a form, writes it in to a text file on the server, and takes the user to a thank you page where the user proceeds browsing through the site. The script is shown below;


#!/usr/bin/perl             #Normal line for cgi scripts

$txt="data.txt";           #Specify location of text file

read(STDIN, $data, $ENV{'CONTENT_LENGTH'});           #get the input

# Split the name-value pairs

@pairs = split(/&/, $data);

foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);

# Convert the HTML encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s///g;

# Convert HTML stuff as necessary.
$value =~ s/<([^>]|\n)*>//g;
$FORM{$name} = $value;
}

# Verify that the required data has been received.

&missing_email unless $FORM{'Email'};

#write to the text file

open TXT, ">>$txt" or die "Cannot open $out for append :$!";

print TXT "\n\n\n";

foreach $x (keys %FORM) {

print TXT "$x: $FORM{$x}\n";
}

#say thanks and exit

print "<HTML><HEAD><TITLE>Thank you for your interest in my
page</TITLE></HEAD><BODY>\n";
print "<FONT SIZE=5 COLOR=#999900><B>Explore my
site</B></font><br>\n";
print "<BLOCKQUOTE>Thank you<B> $FORM{'FirstName'} </B>for your
interest!. Make sure you check out our newest collection of contemporary CD
collection online.....</BLOCKQUOTE>\n";

exit;

sub missing_email
{
print "<HTML><HEAD><TITLE>Missing Email</TITLE></HEAD>\n";
print "<FONT SIZE=5 COLOR=#999900><B>Email field is
blank...</B></FONT>\n";
print "<BR><BR>Please fill in your email address.<P>\n";
print 'Return to the <a href="../signup.htm">Sign up Form</a>.';
print "</BODY></HTML>\n";
exit;
}

The above script can be tested by using the subscribe tool in the home page. Click here to download the zipped file.

Reflector Script
This script actually does just that: It reflect's what a user enter's in to a form in to your web page. The code is really short.

#!/usr/bin/perl

$input=$ENV{'QUERY_STRING'};    #get the query string

@plus=split(/&/, $input);
foreach (@plus) {        #for each parameter
($name, $value) = split(/=/); #get the name and value
$name=~s/\+/ /g; #convert characters
$name=~s/%(..)/pack("c",hex($1))/ge;
$value=~s/\+/ /g;
$value=~s/%(..)/pack("c",hex($1))/ge;
$args{$name}=$value;
#put them in %args }

#The heart of this short script

print "content-type:text/html\n\n";
foreach $x (keys %args) {
print "$x is $args{$x}\n
"; }

Click here to see it in action.

Hello Wolrld Script
My First script definately deserves a spot. Here the 3 line code:


#!/usr/bin/perl

print "Hello, World...\n";

That's it. My current world of CGI. Come back soon to download the best of CGI.

James.

©Maina James Online. All rights reserved.