cgi_passing_parameters
Passing parameters to a CGI script
Some important points:
- The CGI script has to end with .cgi in the name
- It can be placed anywhere in your folder
~/html
- It has to have secure web permissions set – run
mkhomepg
- CGI parameters are passed after
?in the URL, for example: https://hangar118.sdf.org/cgi-bin/foo.cgi?a=1;b=2
- The CGI script gets the parameters via the environment variable
QUERY_STRING
Example session:
# Folder for CGI scripts
$ mkdir ~/html/cgi-bin
# Create file such a this
$ cat ~/html/cgi-bin/foo.cgi
#!/usr/bin/bash
echo 'Content-type: text/html'
echo ''
echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '</head>'
echo '<body>'
echo '<p>Hello World!</p>'
echo '<pre>'
echo "Query (after '?' in the URL): ${QUERY_STRING}"
echo "From: ${HTTP_USER_AGENT}"
echo '</pre>'
echo '</body>'
echo '</html>'
exit 0
# Set executable attribute
$ chmod +x foo.cgi
# Set secure web permissions
$ mkhomepg
setting secure web permissions for /meta/www/h/hangar118
% queing permissions to be set
# Correct permissions would look like this
$ ls -l ~/html/cgi-bin/
total 4.0K
-rwxr-x--- 1 hangar118 www-data 368 Jan 3 02:21 foo.cgi*
It can be invoked via https://hangar118.sdf.org/cgi-bin/foo.cgi?a=1;b=2
Then, in the browser it will produce an output similar to this:
Hello World! Query (after '?' in the URL): a=1;b=2 From: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0
NOTE: The example session is from the MetaArray
cgi_passing_parameters.txt · Last modified: 2023/02/01 05:33 by hangar118