Help! Understanding CGI Scripts: What Am I Looking At?

  • Thread starter Thread starter Math Is Hard
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around understanding CGI scripts, specifically their structure, the languages used to write them, and the role of the shebang line in a script. Participants explore the nature of CGI as a protocol and seek clarification on the components of a simple CGI script example.

Discussion Character

  • Conceptual clarification
  • Technical explanation

Main Points Raised

  • One participant expresses confusion about CGI scripts, noting that CGI does not refer to a specific programming language but rather to scripts written in languages like Perl or PHP.
  • Another participant explains that CGI (Common Gateway Interface) is a protocol for communication between server and client programs, and that CGI scripts can be written in various languages, with Perl being common historically.
  • A participant clarifies that the first line of the example script indicates the location of the Perl interpreter and is standard in UNIX shell scripts, referring to it as a 'shebang'.
  • One participant acknowledges the usefulness of a provided link about CGI, indicating that they found it helpful in their understanding.

Areas of Agreement / Disagreement

The discussion does not appear to reach a consensus, as participants express varying levels of understanding and clarity regarding CGI scripts and their components.

Contextual Notes

Some participants indicate a lack of familiarity with UNIX, which may affect their understanding of the shebang line and its purpose in CGI scripts.

Math Is Hard
Staff Emeritus
Science Advisor
Gold Member
Messages
4,663
Reaction score
36
I am having trouble understanding what CGI scripts are. What I *think* I know about it is that there is no "CGI" language, and when we say CGI script, we mean something written in Perl or Php or some other language that is run on the server. But I could just be utterly confused.

I was looking at this example:

#!/usr/bin/perl -wT
print "Content-type: text/html\n\n";
print "Hello, world!\n";

The 2nd and 3rd lines are written in Perl, I believe. But what is the first? This is just an instruction to the server to tell it the language? And what language is that first line written in? Is it a UNIX OS command? I don't know anything about UNIX, so that may be why I don't know what's going on.

Thanks!:smile:
 
Physics news on Phys.org
anyone? I didn't think these were tough questions...
 
CGI (Common Gateway Interface) is a communication protocol that specifies how programs communicate and send information back and forth between a server and client program.
The Common Gateway Interface, or CGI, is a standard for external gateway programs to interface with information servers such as HTTP servers
A CGI script can be written in any language, but in the early days of httpd were commonly written in Perl

The first line of your Hello World script tells the system where to find the Perl interpreter and is common in all unix shell scripts. Basically it tells the system what interpreter to use to execute the commands contained in the file.

The #! is called a 'shebang'

http://hoohoo.ncsa.uiuc.edu/cgi/
CGI on Wikipedia
 
Last edited by a moderator:
Thanks, imabug.

I just came across that first link you posted this afternoon and it has been helpful. I looked at the Wiki info earlier, but it didn't clear it up for me at all.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
Replies
2
Views
2K
  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • Sticky
  • · Replies 0 ·
Replies
0
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • Sticky
  • · Replies 1 ·
Replies
1
Views
17K
Replies
2
Views
3K
Replies
8
Views
3K