Shell实现cgi接口示例

ls -l /var/www/cgi-bin/
-rwxrwxrwx 1 root root 391 Dec 30 14:54 hello.cgi

#!/bin/sh
#下面两行非常重要否则会出现http500的错误。
echo "Content-type:text/html";
echo "";
echo "<html>";
echo "<head><title>Test for Shell Cgi-Bin</title></head>";
echo "<body>";
echo "<h1>Hello, andylin! Welcome to \"The Congfeng's World\"</h1>";
echo "<h2>";
echo "Content Type:$CONTENT_TYPE <br>";
echo "Content Length:$CONTENT_LENGTH <br>";
echo "Query string:$QUERY_STRING <BR>";
echo "</h2>";
echo "</body>";
echo "</html>";

 

 

访问:http://127.0.0.1/cgi-bin/hello.cgi?adsfssadf

 

显示:

Hello, andylin! Welcome to "The Congfeng's World"

Content Type:
Content Length:
Query string:adsfssadf

你可能感兴趣的:(html,cgi)