html初始如下:
test
Hello World.
链接,指向cgi脚本程序
Display the Date
Is Laura Logged in?
pinglaura脚本:
#!/bin/bash
echo -e "Content-type: text/html"
echo
echo -e ""
echo -e "Is Laura There? "
echo -e ""
ison=`who | grep Laura`
if [ ! -z "$ison" ]; thenecho -e "Laura is logged in"
elseecho -e "
Laura isn't logged in"
fi
echo -e ""
为了传递一个参数给脚本,可以在URL中使用 (?) 插入脚本名词和参数之间, 用加号(+) 表示每个单一的参数, 如:
Is John Logged in?
也可以直接修改路径信息
http://myhost/cgi-bin/myscript/remaining_path_info?arg1+arg2
pinggeneric脚本:
#!/bin/bash
echo -e "Content-type: text/html"
echo
echo -e ""
echo -e "Is Laura There? "
echo -e ""
ison=`who | grep "${1}"`
if [ ! -z "$ison" ]; thenecho -e "$1 is logged in"
elseecho -e "
$1 isn't logged in"
fi
echo -e ""
CGI输出不是非得一个数据流,有时可以告诉浏览器是存在服务器上的一个页
Location: ../docs/final.html
不能Content-type 和 Location两个输出同时使用。
只是要从用户那儿收集点信息,什么都不改变。
echo Status: 204 No Response
echo
大多数表单有两个部分: HTML的表单格式;处理表单数据的CGI脚本. 这个CGI脚本使用标签属性调用
表单从浏览器发给服务器有两种方法. GET 和 POST。
上面谈论的方法,实际是GET,它将数据打包放置在环境变量QUERY_STRING中作为URL整体的一部分传递给服务器。
theName=Ichabod+Crane&gender=male&status=missing&headless=yes
因为表单输入是用这个URL编码传递给你的脚本的,在你用这些参数之前必须解码,因为解码是个很普遍的工作,可以有很多工具做这个工作 . 你没有必要自己写这个解码程序。
uncgi的解码程序, 你可以从http://www.hyperion.com/~koreth/uncgi.html. 得到原码,安装在你自己的cgi-bin目录下。
#!/bin/bash
echo -e "Content-type: text/html"
echo
echo -e ""
echo -e "Hello "
echo -e ""
echo -e ""
if [ ! -z "$WWW_theName" ]; thenecho -e "Hello, "echo -e $WWW_theName
elseecho -e "You don't have a name?"
fi
echo "
"
echo ""