CGI
Common Gateway Interface
Back-end, web server, technology.
- Learn, Guides,...
- Libraries with scripts
- See also HTTP error codes when a CGI fail to execute appropriately
- Examples (< may fail depending on server config - if dir listing is allowed or not) (all direct links below opens in a sep. window/tab):
printenv.pl:
#!/usr/local/bin/perl -wT use strict; use diagnostics; $|++; print "Content-Type: text/html\n\n"; print "<HTML><HEAD><TITLE>Printenv Script</TITLE></HEAD>\n"; print "<BODY>\n"; print map { "<P><B>$_</B> = $ENV{$_}</P>\n" } sort keys %ENV; print "</BODY></HTML>\n";
$$$. dd
ddd
Results from another printenv script, as static text, actual execution - only works if server is configured accordingly (not on Internet): http://localhost:8888/cgi-bin/printenv.
400 Bad Request
500 Internal Server Error
The server encountered an unexpected condition which prevented it from fulfilling the request.
A Mac-encoded text file - uses CR for line breaks |
cmdprompt> less printenv.cgi |
A UNIX (and DOS)-encoded text file - uses LF for line breaks |
cmdprompt> less printenv.pl #!/usr/local/bin/perl -wT use strict; use diagnostics; $|++; print "Content-Type: text/html\n\n"; print "<HTML><HEAD><TITLE>Printenv Script</TITLE></HEAD>\n"; print "<BODY>\n"; print map { "<P><B>$_</B> = $ENV{$_}</P>\n" } sort keys %ENV; print "</BODY></HTML>\n"; [johan@jp2] comgt/search> |
PHP as CGI |
PHP as Module |
|
Script file | ||
Must have Executable flag set | Yes, get Internal error otherwise | No |
|
|
|
Running the above script in Module-mode will provide browser output: #!/usr/bin/env php Content-Type: text/html Hello, World |
|
|
Test material/script | php-as-cgi / show_env.php | php-as-cgi / show_env.php |
php.net .. reserved.variables.php
|
per (2016-02-03) | 1&1 | IM2713 |
Server API | CGI/FastCGI | Apache 2.0 Handler |
Updated 2016-02-03