Form ... | Table ... | Server Side code ... |
Perl CGI script example... | Microsoft Active Server Page (ASP) example... | Microsoft Active X function to append to a local gbook file for testing...
We have the ability to append data to a guestbook, download it, and format it using JavaScript using the client's browser. You need to understand what the javascript does on this page, but you do not need much knowledge about CGI scripts or Webservers, or connecting to databases. You can get simple applications up and running fast. How to make it pay.
You need to give write permission to your gbookFuncDemo.js file so that the CGI script can write to it.
The perl for the CGI script is:
#!/usr/bin/perl ############################################################################## # Guestbook Version 2.3.1 ++ # # Copyright 1996 Matt Wright mattw@worldwidemart.com # # Created 4/21/95 Last Modified 10/29/95 # # Scripts Archive at: http://www.worldwidemart.com/scripts/ # ############################################################################## # COPYRIGHT NOTICE # # Copyright 1996 Matthew M. Wright All Rights Reserved. # # # # Guestbook may be used and modified free of charge by anyone so long as # # this copyright notice and the comments above remain intact. By using this # # code you agree to indemnify Matthew M. Wright from any liability that # # might arise from it's use. # # # # Selling the code for this program without prior written consent is # # expressly forbidden. In other words, please ask first before you try and # # make money off of my program. # # # # Obtain permission before redistributing this software over the Internet or # # in any other medium. In all cases copyright and header must remain intact.# ############################################################################## # Set Variables #$N is used to store the number in ?guestbook=n $N=""; #$X is an extension that allows multiple arrays $X=""; #SERVER_URL=http://127.0.0.1/ if ( $ENV{'SERVER_URL'} eq 'http://127.0.0.1/' ){ $guestbookreal = 'C:\\Xitami\\webpages\\gbook'; $guestbookjs = 'C:\\Xitami\\webpages\\gbook'; $guestbookjsf = 'C:\\Xitami\\webpages\\gbookF'; $passwordfile = 'C:\\Xitami\\webpages\\cgi-bin\\password.txt'; $creditfile = "$ENV{'DOCUMENT_ROOT'}\\credits.js"; } else { $guestbookreal = $ENV{'DOCUMENT_ROOT'}.'/public/gbook'; # for outputAsHTML() $guestbookjs = $ENV{'DOCUMENT_ROOT'}.'/public/gbook'; # for outputAsJSarrays() $guestbookjsf = $ENV{'DOCUMENT_ROOT'}.'/public/gbookF'; # for outputAsJSfunctions() $passwordfile = $ENV{'DOCUMENT_ROOT'}.'/password.txt'; $creditfile = $ENV{'DOCUMENT_ROOT'}.'/credits.js'; } #$date_command = "/usr/bin/date"; # Set Your Options: $separator = 1; # 1 = <hr>; 0 = <p> $entry_order = 1; # 1 = Newest entries added first; # 0 = Newest Entries added last. $allow_html = 1; # 1 = Yes; 0 = No $line_breaks = 0; # 1 = Yes; 0 = No # Done ############################################################################## # Get the Date for Entry $date = "System Date"; #`$date_command +"%A, %B %d, %Y at %T (%Z)"`; chop($date); # output date so that the web pages can be use the javascript: now= new Date( postedOn ) #IE 5 formats #Tue Jun 25 06:47:32 UTC+0100 2002 #toString(): #Tue Jun 25 06:47:32 UTC+0100 2002 #toGMTString(): #Tue, 25 Jun 2002 05:47:32 UTC #toLocaleString(): #06/25/2002 06:47:32 #toUTCString(): #Tue, 25 Jun 2002 05:47:32 UTC # # #Netscape Navigator #Tue Jun 25 06:49:59 GMT+0100 (GMT Daylight Time) 2002 #toString(): #Tue Jun 25 06:49:59 GMT+0100 (GMT Daylight Time) 2002 #toGMTString(): #Tue, 25 Jun 2002 05:49:59 GMT #toLocaleString(): #Tuesday, June 25, 2002 06:49:59 #toUTCString(): #Tue, 25 Jun 2002 05:49:59 GMT # #($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # 0 1 2 3 4 5 6 7 8 @t = localtime(); @days= ('Sun','Mon','Tue','Wed','Thu','Fri','Sat','Sun'); @months=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); $fullYear=1900+$t[5]; #original format #$date = " $days[$t[6]] $t[3]/$months[$t[4]]/$fullYear at $t[2]: $t[1]: $t[0] "; #toString(): #Tue Jun 25 06:47:32 UTC+0100 2002 $date = "$days[$t[6]] $months[$t[4]] $t[3] ".substr("0".$t[2],-2,2).":".substr("0".$t[1],-2,2).":".substr("0".$t[0],-2,2)." UTC+0100 $fullYear "; #toUTCString(): #Tue, 25 Jun 2002 05:47:32 UTC $date = "$days[$t[6]], $t[3] $months[$t[4]] $fullYear ".substr("0".$t[2],-2,2).":".substr("0".$t[1],-2,2).":".substr("0".$t[0],-2,2)." UTC+0100"; # Split the name-value pairs @pairs = split(/&/, $ENV{'QUERY_STRING'}); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/<!--(.|\n)*-->//g; if ($allow_html != 1) { $value =~ s/<([^>]|\n)*>//g; } $FORM{$name} = $value; } # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; # Leave the value mostly escaped as JavaScript can unescape easily. # Convert CR LF and LF $value =~ s/%0D//g; $value =~ s/%0A/<BR>\\\n/g; # Convert \ " and '' $value =~ s/%5C/\\\\/g; $value =~ s/%22/\\"/g; $value =~ s/%27/\\'/g; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORMJS{$name} = $value; $value =~ s/<!--(.|\n)*-->//g; if ($allow_html != 1) { $value =~ s/<([^>]|\n)*>//g; } $FORM{$name} = $value; } # load passwords # read passwords into associative array # # store the passwords #GBOOK=password # Get Membership details if ( -e $passwordfile ) { open (PASSWORDFILE,$passwordfile ) || &file_error( PASSWORDFILE, $passwordfile ); # die "Can't Open $passwordfile: $!\n"; @PASSWORD_LINES=<PASSWORDFILE>; close(PASSWORDFILE); $PASSWORD_SIZE=@PASSWORD_LINES; foreach $memRow (@PASSWORD_LINES){ ($name, $value) = split(/,/, $memRow); $PASSWORDSA{$name} = $value; } $password = $FORM{'password'}; $guestbook = $FORM{'guestbook'}; $validpassword = $PASSWORDSA{$guestbook}; #if ( ( $password ne '' ) && ( $password ne $validpassword ) ) { #if ( $password ne '' ) { if ( $password ne $validpassword ) { $PASSWORDSA{$name} = $value; # Print Beginning of HTML print "Content-Type: text/html\n\n"; print "<html><head><title>Thank You</title></head>\n"; print "<body><h1>INVALID PASSWORD :$guestbook: wanted:$validpassword: got :$password:, press back </h1>\n"; foreach $memRow (@PASSWORD_LINES){ ($name, $value) = split(/,/, $memRow); print "<body><h1>PASSWORDS :$PASSWORDSA{$name}:$name:$value:, press back </h1>\n"; $PASSWORDSA{$name} = $value; } print "<body><h1>Wanted :$validpassword:, press back </h1>\n"; print "<body><h1>Your data has not been added, press back </h1>\n"; print "<H1><A HREF=$FORM{'nextpage'} target=_top > return... <A></H1>"; print '</body></htmr>\n'; exit; } } # Open Link File to Output $N = "$FORM{'guestbook'}"; &outputAsJSfunctions(); if ( $FORM{'loadnextpage'} ){ # Print Out Initial Output Location Heading print "Location: $FORM{'nextpage'}\n\n"; exit; } &no_redirection(); exit; ####################### # Subroutines # Redirection Option sub no_redirection { # Print Beginning of HTML print "Content-Type: text/html\n\n"; print "<html><head><title>Thank You</title></head>\n"; print "<body><h1>Thank You For your submission</h1>\n"; print "<H1><A HREF=$FORM{'nextpage'} target=_top > return... <A></H1>"; print '</body></htmr>'; exit; print "<HR> Some links back to places known by this frame<SCRIPT>\n"; print ' var ref_HTTP = "'."$ENV{ 'HTTP_REFERER' }".'";'."\n"; print ' var ref_doc =document.location.href;'."\n"; print ' var ref_par =parent.location.href;'."\n"; print ' var ref_par =parent.location.href;'."\n"; print ' var ref_cur =history.current;'."\n"; print 'self.document.write( "<p><A HREF="+ref_HTTP+" > return... to HTTP_REFERER: "+ref_HTTP+"<A>"); '."\n"; print 'self.document.write( "<BR><A HREF="+ref_doc+" > return... to document.location.href: "+ref_doc+" <A>"); '."\n"; print 'self.document.write( "<BR><A HREF="+ref_par+" > return... to parent.location.href: "+ref_par+" <A>"); '."\n"; print 'self.document.write( "<BR><A HREF="+ref_cur+" > return... to window.current: "+ref_cur+" <A>"); '."\n"; print '</SCRIPT>'."\n"; print "<HR> Webhoster Env Vars\n"; while (($key,$value) = each %ENV) { print "<BR>$key=$value\n"; } print '</body></htmr>'; exit; } # file_error - call if problems opening files sub file_error { local($FH, $fileName) = @_; # Print Beginning of HTML print "Content-Type: text/html\n\n"; print "<html><head><title>Thank You</title></head><body>\n"; print "<H1>Error Opening File $fileName:, press back</h1> \n"; print "Your data has not been added, press back <P>\n"; print "If you can log into the server, check file permissions\n"; print '</body></htmr>'; exit; } # # outputAsHTML - write guestbook data as HTML to gbookXXX.htm # #<HR><BR> #<B>From: </B><BR> #<B>email: </B><A HREF=mailto:></A><BR> #<B>IP Address: </B>213.1.74.249<BR> #<B>postedOn:</B>System Date<BR> #<B>: </B><BR> #<B>: </B><BR> #<B>: </B><BR> #<B>: </B><BR> #<BR> sub outputAsHTML { open (GUEST,">$guestbookreal$N.htm") || die "Can't Open $guestbookreal$N: $!\n"; #Now seek end of guestbook which is indicated by <!--begin--> for ($i=0;$i<=$SIZE;$i++) { $_=$LINES[$i]; # found insertion point if (/<!--begin-->/) { if ($entry_order eq '1') { print GUEST "<!--begin-->\n"; } print GUEST "<BR>\n<B>From: </B>$FORM{'name'}<BR>\n"; print GUEST "<B>email: </B><A HREF=mailto:$FORM{'email'}>$FORM{'email'}</A><BR>\n"; print GUEST "<B>IP Address: </B>$ENV{'REMOTE_ADDR'}<BR>\n"; print GUEST "<B>postedOn:</B>$date<BR>\n"; print GUEST "<B>$FORM{'usertitle1'}: </B>$FORM{'userfield1'}<BR>\n"; print GUEST "<B>$FORM{'usertitle2'}: </B>$FORM{'userfield2'}<BR>\n"; print GUEST "<B>$FORM{'usertitle3'}: </B>$FORM{'userfield3'}<BR>\n"; print GUEST "<B>$FORM{'usertitle4'}: </B>$FORM{'userfield4'}<BR>\n"; #change new lines into <BR> $FORM{'comments'} =~ s/\cM\n/<br>\n/g; print GUEST "$FORM{'comments'}<BR>\n"; print GUEST "<HR>"; if ($entry_order eq '0') { print GUEST "<!--begin-->\n"; } } else { print GUEST $_; } } close (GUEST); } # # outputAsJSarrays - write guestbook data as new elements in JS array to gbookXXX.js # #// new amendement Results:: # #gbA[ count ] = new GB( #//HTTP_REFERER = http://127.0.0.1/priv/apsc/results/funcBasicForm.htm #//HTTP_USER_AGENT= Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; DigExt; nw2) # "name", # "email", # " sun 23/Jun/2002 at 20: 51: 45 ", # "127.0.0.1", # "userfield1", # "userfield2", # "userfield3", # "userfield4", # "" # ); # count=count+1; sub outputAsJSarrays { #HTTP_REFERER=http://127.0.0.1/priv/apsc/events.htm #HTTP_USER_AGENT=Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; DigExt; nw2) open (GUESTJS,">>$guestbookjs$N.js") || &file_error( GUESTJS, "$guestbookjs$N.js" ); #die "Can't Open $guestbookreal: $!\n"; $X = "$FORMJS{'guestBookArrayName'}"; print GUESTJS "\n"; print GUESTJS "// new amendement $N:$X: \n"; print GUESTJS "\n"; print GUESTJS "gbA$X\[ count$X \] = new GB( \n"; print GUESTJS "//HTTP_REFERER = $ENV{'HTTP_REFERER'}\n"; print GUESTJS "//HTTP_USER_AGENT= $ENV{'HTTP_USER_AGENT'}\n"; print GUESTJS " \"$FORMJS{'name'}\",\n"; print GUESTJS " \"$FORMJS{'email'}\",\n"; print GUESTJS " \"$date\",\n"; print GUESTJS " \"$ENV{'REMOTE_ADDR'}\",\n"; print GUESTJS " \"$FORMJS{'userfield1'}\",\n"; print GUESTJS " \"$FORMJS{'userfield2'}\",\n"; print GUESTJS " \"$FORMJS{'userfield3'}\",\n"; print GUESTJS " \"$FORMJS{'userfield4'}\",\n"; print GUESTJS " \"$FORMJS{'comments'}\"\n"; print GUESTJS " );\n"; print GUESTJS " count$X=count$X+1;\n"; close (GUESTJS); } # # outputAsJSfunctions - write guestbook data as functions to gbookFXXX.js # #// new amendement Results:_team: # #//HTTP_REFERER = http://127.0.0.1/priv/apsc/results/funcBasicForm.htm #//HTTP_USER_AGENT= Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; DigExt; nw2) #gbF_team( #"name","email"," sun 23/Jun/2002 at 20: 52: 0 ", #"127.0.0.1", #"userfield1", #"userfield2", #"userfield3", #"userfield4", #"" #); sub outputAsJSfunctions { # New format open (GUESTFJS,">>$guestbookjsf$N.js") || &file_error( GUESTJS, "$guestbookjsf$N.js" ); # die "Can't Open $guestbookjsf$N.js: $!\n"; $X = "$FORMJS{'guestBookArrayName'}"; print GUESTFJS "\n"; print GUESTFJS "// new amendement $N:$X: \n"; print GUESTFJS "\n"; print GUESTFJS "//HTTP_REFERER = $ENV{'HTTP_REFERER'}\n"; print GUESTFJS "//HTTP_USER_AGENT= $ENV{'HTTP_USER_AGENT'}\n"; print GUESTFJS "gbF$X( \n"; print GUESTFJS "\"$FORMJS{'name'}\","; print GUESTFJS "\"$FORMJS{'email'}\","; print GUESTFJS "\"$date\",\n"; print GUESTFJS "\"$ENV{'REMOTE_ADDR'}\",\n"; print GUESTFJS "\"$FORMJS{'userfield1'}\",\n"; print GUESTFJS "\"$FORMJS{'userfield2'}\",\n"; print GUESTFJS "\"$FORMJS{'userfield3'}\",\n"; print GUESTFJS "\"$FORMJS{'userfield4'}\",\n"; print GUESTFJS "\"$FORMJS{'comments'}\"\n"; print GUESTFJS ");\n"; close (GUESTFJS); }
Include the following Javascript so that the form's data can be saved in the format that the cgi script outputs:
<script> // ------ACTIVE X functions to emulate the server and scripts by saving direct to local disk. var f = window.document.forms[ "F1" ] // /D:\data\hp\gbbook\DHRsorted.htm var s s = self.location.pathname // gives /D:\data\hp\gbbook\DHRsorted.htm s = s.replace( /\//g,"") // remove leading / s = s.replace( /DHRform.htm/g,"gbookF_ASP.js" ) // remove file name f.guestbookPath.value=s function strip ( s ) { s= s.replace( /\\/g,"\\\\") s= s.replace( /\"/g,"\\\"") s= s.replace( /\'/g,"\\\'") s= s.replace( /\n/g,"") s= s.replace( /\r/g,"<BR>\\n") return s } function AXopFile( formName,guestbook ){ var f = window.document.forms[ formName ] var fs,s; var now = new Date() //var gbook = GetAbsolutePathName( "gbookF"+guestbook+".js" ) //var gbook = "C:\\iishelp\\iis\\htm\\tutorial\\gbookF"+guestbook+".js" gbook=f.guestbookPath.value alert( gbook ) // fs = new ActiveXObject("Scripting.FileSystemObject"); // fs.CreateTextFile( "test1.txt",true ); // Create a file // s = fs.Writeline( f.csv.value ); // fs.Close(); var fs = new ActiveXObject("Scripting.FileSystemObject"); //var ts = fs.CreateTextFile("test1.txt", true); if ( ! fs.FileExists( gbook ) ) { fs.CreateTextFile( gbook ) } var ts = fs.OpenTextFile( gbook ,8 , 0 ); ts.WriteLine("//Appended using Active X."); //' for Array format //' ts.WriteLine( "gbA" + f.guestBookArrayName.value + "[ count" + f.guestBookArrayName.value + " ] = new GB( ") ts.WriteLine( "gbF" + f.guestBookArrayName.value + "( ") ts.WriteLine( "'" + strip ( f.name.value ) + "',") ts.WriteLine( "'" + f.email.value + "',") ts.WriteLine( "'" + now + "',") ts.WriteLine( "'127.0.0.1'," ) ts.WriteLine( "'" + strip ( f.userfield1.value ) + "',") ts.WriteLine( "'" + strip ( f.userfield2.value ) + "',") ts.WriteLine( "'" + strip ( f.userfield3.value ) + "',") ts.WriteLine( "'" + strip ( f.userfield4.value ) + "',") ts.WriteLine( "'" + strip ( f.comments.value ) + "'") ts.WriteLine( ");" ) ts.WriteLine( " " ) //'' count = count+ 1 //' ts.WriteLine( "count" + f.guestBookArrayName.value + "=count" + f.guestBookArrayName.value + "+1; " ) ts.Close(); alert( " thanks for your submission ") } </script>
The code in the following zip file should be unpacked into a directory off the desktop. It contains an example that allows the form data to be appended to the gbookF_ASP.js files also stored in that directory. It is included in the example web pages. The formatting is nothing special, just anything to show that something can be done.
<% @ LANGUAGE="VBSCRIPT" %> <% OPTION EXPLICIT DIM L_Guestbook, count, CursorType, intMID,objConn ,rst, strProvider, strQuery, StrSort ' NOTE: This script does not replace ' " \ CR or LF which will corrupt the data and add syntax errors. ' pick up form variables %> <HTML> <HEAD> <TITLE>Guest Book</TITLE> </HEAD> <body bgcolor="#FFFFFF" text="#000000"><font face="Verdana,Arial,Helvetica"> <A href="DHRform.htm"> DHRform.htm </A> | <A href="DHRop.htm"> DHRop.htm </A> | <A href="DHRop.asp"> DHRop.asp </A> <H1>about to save file</H1> <% Function strip( ByVal s) s = replace(s,chr( 92 ),Chr( 92 ) & Chr( 92 )) ' first double up any \ s = replace(s,chr( 39 ),Chr( 92 ) & Chr( 39 )) ' now escape ' s = replace(s,chr( 34 ),Chr( 92 ) & Chr( 34 )) ' now escape " ' Not really sure about how to escape < > < and > ' s = replace(s,"<","<") ' now escape < ' s = replace(s,">",">") ' now escape > ' now replace CR LF and LF s = replace(s,vbCr,"") s = replace(s,vbLf,"<BR>\"+vbCr+vbLf) strip = s End Function Const ForReading = 1, ForWriting = 2, ForAppending = 8 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 Dim fs, f, ts, s, gbook Set fs = CreateObject("Scripting.FileSystemObject") gbook = server.mappath("gbookF"& request.Form("guestbook")&".js") if ( not fs.FileExists( gbook ) ) Then fs.CreateTextFile gbook 'Create a file End If Set ts = fs.OpenTextFile( gbook, ForAppending,TristateFalse) ' guestBookFile1[ count ] = new GB( ' or ' gbF( ' "name", ' "email", ' " Mon 5/Nov/2001 at 18: 3: 37 ", ' "132.146.89.88", ' "userfield1", ' "userfield2", ' "userfield3", ' "userfield4", ' "" ' ); ' the next is required for the arrays ' count=count+1; '' for Array format ' ts.WriteLine( "gbA" & request.Form("guestBookArrayName") & "[ count" & request.Form("guestBookArrayName") & " ] = new GB( ") ts.WriteLine( "gbF" & request.Form("guestBookArrayName") & "( ") ts.WriteLine( "'" & strip ( request.Form("name") ) & "',") ts.WriteLine( "'" & request.Form("email") & "',") ts.WriteLine( "'" & now & "',") ts.WriteLine( "'" & Request.ServerVariables("REMOTE_ADDR") & "',") ts.WriteLine( "'" & strip ( request.Form("userfield1") ) & "',") ts.WriteLine( "'" & strip ( request.Form("userfield2") ) & "',") ts.WriteLine( "'" & strip ( request.Form("userfield3") ) & "',") ts.WriteLine( "'" & strip ( request.Form("userfield4") ) & "',") ts.WriteLine( "'" & strip ( request.Form("comments") ) & "'") ts.WriteLine( ");" ) ts.WriteLine( " " ) '' count = count+ 1 ' ts.WriteLine( "count" & request.Form("guestBookArrayName") & "=count" & request.Form("guestBookArrayName") & "+1; " ) ts.Close %> <%= server.mappath(Request.ServerVariables("PATH_INFO"))%><BR> <%= server.mappath("gbookF"& request.Form("guestbook")&".js")%><BR> <SCRIPT LANGUAGE="JavaScript"> function gbF( name,email,postedOn,IPaddress,userfield1,userfield2,userfield3,userfield4,comments ){ self.document.write( "<h2>"+name+"@"+postedOn+"</h2><BR>"+userfield1+"<BR>"+userfield2+"<BR>"+userfield3+"<BR>"+userfield4+"<BR>"+comments+"<HR>") } function gbF_team( name,email,postedOn,IPaddress,userfield1,userfield2,userfield3,userfield4,comments ){ self.document.write( "<h2>"+name+"@"+postedOn+"</h2><BR>"+userfield1+"<BR>"+userfield2+"<BR>"+userfield3+"<BR>"+userfield4+"<BR>"+comments+"<HR>") } <% ' Dim retstring ' ' Set s = fs.OpenTextFile("gbookF"& request.Form("guestbook")&".js",ForReading, TristateUseDefault) ' ' Do While s.AtEndOfStream <> True ' retstring = s.ReadLine ' response.write( retstring ) ' ' Loop ' s.Close %> </script> Thank you for your contribution. <h1><A HREF='<% request.Form("nextpage") %>' target=_top > return... <A></H1> </font></BODY> </HTML>
This is a difficult question, especially when my ISP give free space, and free downloads. My ISP limits webhosting such that the page owner has to upload pages via a dial up connection. This guestbook idea would allow the website owner to allow anybody to upload 'content'. If the generic CGI script referred to a credits file, every time the script is run, it could use up some of the credit. After a number of uses, the script uses up all the credit and stops functioning.
In my example, my CGI script refers to a file called credits.js and contains the line: credits=123 . When the script is run, this is constrained to be 0 <= credits < 1000 say, to prevent unlimited usage. If the CGI sucessfully decrements this and re-writes the file, it goes on to process the form data, but only if you have remaining credit.
There are two ways to replenish the credit:
The perl code would look something like this:
#----------------------------------------------------------------- # Check the credits open (CREDITFILE,$creditfile ) || &file_error( CREDITFILE,$creditfile ); @CREDIT_LINES=<CREDITFILE>; close(CREDITFILE); $CREDIT_SIZE=@CREDIT_LINES; foreach $memRow (@CREDIT_LINES){ ($name, $value) = split(/=/, $memRow); #print "$name, $value<P>\n"; $CREDITSA{$name} = $value; } #print "<h1> Credits $CREDITSA{'credits'} </h1>"; # if blank create if ( $CREDITSA{'credits'} eq '' ) { $CREDITSA{'credits'}=1000; } $credits = $CREDITSA{'credits'}-1; #print "This guestbook server has $credits credits left<P>\n"; # if fraudlently set to -ve value if ( $credits > 1000 ) { $credits=1000; } open (CREDITFILE,">$creditfile" ) || &file_error( CREDITFILE,$creditfile ); print CREDITFILE "credits=$credits\n"; close(CREDITFILE); if ( $credits < 0 ) { #print "<h1> Credits run out, data not appended </h1>"; exit; } #--------------------------------------------------------------------
This page was last updated on: