User Tools

Site Tools


cgi_passing_parameters
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


cgi_passing_parameters [2023/02/01 05:33] (current) – created hangar118
Line 1: Line 1:
 +====== 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:
 +
 +<code>
 +
 +# 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*
 +
 +</code>
 +
 +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:
 +
 +<code>
 +
 +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
 +
 +</code>
 +
 +NOTE: The example session is from the MetaArray
  
cgi_passing_parameters.txt · Last modified: 2023/02/01 05:33 by hangar118