With php, you don't need a cgi-bin, because the code is embedded in the HTML page. php3 is probably a simple way to do it, but the available source code is limited.
Perl has tons of available source code, with plenty of scripts that do exactly what you're looking for, free of charge.
Have a look around cgi-resources.com (http://cgi-resources.com) , you're guaranteed to find something...
adam