Some examples of Using Perl and C Through your Web browser
- testscript.pl
- Some random examples of perl including form submit, system calls, calling a c-program, and using both arrays and hashes.
- testmult.html
- An example of submitting a form to a C program using get method
- testmultpost.html
- Does the same as the previous example but uses the post method instead of the get method. Notice that in the post method there is nothing extra in the URL
- Java Applet Example
- This is a very quickly done example of putting an applet into a website. Note that I put the .class file into the same folder as the .html file displaying it. This program requires no other images to be in the directory, but some applets might use images. If so, they have to be in the same directory as the html page (or as specified by the specific applet in a readme file or on their website, etc)
A few other notes:
- I have public_html chmodded to 711
- So is cgi-bin
- Compile your c program by "gcc -o xxxx.cgi filename.c" (or however you compile it, if you have multiple steps or multiple .c files, just change the line where you make the exe to call it xxxx.cgi)
- Make sure the .cgi file is inside cgi-bin
- the file xxxx.cgi has to be chmodded to 700 . This is very important. If you do 777 the CS computers won't allow it.
- Then to create a form that calls the c program on submit do < form action="xxx.cgi" > (note that you should be able to view the source of the HTML document with the form on it)
- Of course, if you have your html file in public_html and the .cgi file in cgi-bin, you'll have to make your form action="cgi-bin/xxxx.cgi" or action="http://www.cs.mcgill.ca/username/cgi-bin/xxxx.cgi
- Also note that if you put an html file inside cgi-bin (or any file for that matter--such as pictures that you are displaying), you have to make sure they are readable. So to do this, chmod that individual file to 744. You probably can change the entire directory of cgi-bin to be chmodded to 755 (instead of 711) and then you wouldn't have to change each *.jpg or *.html etc file, but I haven't tested this.
- So if you have a website.html with a picture.jpg in cgi-bin and this page has a form which calls helloworld.cgi, you should either put website.html inside public_html and then do action="cgi-bin/helloworld.cgi" OR put website.html and picture.jpg into cgi-bin, do action="helloworld.cgi" and chmod website.html and picture.html to 744. Either way, chmod cgi-bin to 711 and put helloworld.cgi into cgi-bin, chmodding it to 700.