“Retrofit” the form data string above:
name=Evan+Burke&card=Visa&number=8443261344895544&order=French+perfume
for buying some French perfume into the HTML form fields and submit button on the Web page form.
My scripts are as follow:

The screen shot of running the program is as follow:

2. Write the script
Script archives exist for PERL, Python and JavaScript. Search the Web for a script that processes the HTML forms data. Read the code and list the steps involved in processing the form.
The scripts I found from the web is as follow, and the steps are very self-explanatory.
#!/usr/bin/python
import sys
import time
import cgi
sys.stderr = sys.stdout
# Read in a template for the page we're to generate
fh = open ("template.htp")
html = "".join(fh.readlines())
# Read in the form contents and save them in a dictionary
inputs = cgi.FieldStorage()
fill = {}
for key in inputs:
fill[key] = inputs[key].value
# Do Work!
# Use values in input to create values in fill
matched = lines = 0
fval = fill.get("code","")
if fval != "":
fill["result"] = "Dialling codes starting " + fill["code"]
fhdata = open("../../live_html/data/stdcodes.xyz")
while 1:
line = fhdata.readline();
if line == "": break
if line.startswith(fval):
fill["result"]+= "
" + line
matched += 1
lines += 1
fill["result"] += "
matched "+str(matched)+ \
" out of "+str(lines)
else:
fill["result"] = "Your results will appear here"
fill["time"] = str(time.time());
# Fill in the response template
for key in fill:
lookfor = "%"+key+"%"
html = html.replace(lookfor,fill[key])
# Send out the results
print "Content-type: text/html\n\n",html
3.Can you modify the script to process the form?
Yes, I can but I would not because it is quite simple already.
No comments:
Post a Comment