CGI Programming Interview Questions and Answers
Q1. What is CGI?
Ans: The Common Gateway Interface, or CGI, is a popular for external gateway packages to interface with records servers together with HTTP servers. A undeniable HTML record that the Web daemon retrieves is static, which means that it exists in a consistent country: a textual content file that doesn’t change.
A CGI application, however, is accomplished in actual-time, so that it can output dynamic records.
Q2. Is CGI a script or a software?
Ans: The distinction is semantic. Traditionally, compiled executables(binaries) are referred to as packages, and interpreted applications are typically called scripts. In the context of CGI, the distinction has grow to be even more blurred than earlier than. The phrases are regularly used interchangeable.
Q3. What is the difference between an interpreted language and a compiled language?
Ans: A compiled language is written and then run through a compiler which exams its syntax and compresses it right into a binary executable. Since an interpreted language isn't always compiled, it must be checked for errors at run-time, which makes it quite a chunk slower than a compiled language (like C or Java). Perl is an example of an interpreted language. Remember, although, that just due to the fact a language is interpreted does not always imply it is not full-featured, or simplistic. Perl can get very complicated and really cryptic, in no time.
Q4. What is the difference among Java and CGI?
CGI is a common gateway interface and it's far a protocol this is used to run packages on WWW servers. Whereas, Java is having its very own popular APIs to, run the programs on WWW servers.
CGI is having very excessive response whilst developing the Operating system shell. Whereas, Java is a mild platform in giving the reaction when, developing the shell.
CGI isn't very scalable and no longer a comfortable item orientated platform to apply. Whereas, Java is object oriented and very secure.
CGI doesn’t have the separation among the presentation and business common sense. Whereas, Java defines, the separation in a totally easy manner and hold the whole lot logically positioned.
CGI is platform based scripting language whereas, Java is platform independent language.
Q5. When do I want to apply CGI?
Ans: There are innumerable caveats to this solution, however essentially any Webpage containing a shape would require a CGI script or application to process the form inputs.
Q6. How can I run my CGI program ‘stay’ in a debugger?
Ans: At First, inside the CGI code, at it’s begin, add “sleep (30);” This will purpose the CGI to do not anything for thirty seconds (you may need to adjust this time). Compile the CGI with debuging data (“-g” in gcc) and set up the CGI as regular. Next, using your web browser, spark off the CGI. It will of course simply sit down there doing nothing. While it's miles ‘sleeping’, discover it’s PID(playstation -a and fix to that PID(“connect <pid>” in gdb). You will even want to tell it wherein to find the symbol definitions (“symbol-report <cgi>” in gdb). Then set a spoil factor after the invocation of the sleep function and you are prepared to debug. Do be conscious that your browser will ultimately timeout if it doesn’t acquire something.
Q7. How can I stop my CGI script analyzing and writing files as “no one”?
Ans: CGI scripts are run with the aid of the HTTPD, and consequently by means of the UID of the HTTPD system, which is (through convention) commonly a special consumer “no one”.
Q8. What is a CGI bin listing?
Ans: A CGI bin directory is a special listing at the server in which CGI scripts are allowed to be performed. Most servers are configured to most effective permit CGI scripts to be executed from one vicinity, so that you can decrease safety holes. Poorly written scripts can wreak havoc on a server if allowed to run unchecked – maximum gadget admins will want to verify that the script isn't doing some thing malicious before letting you run it.
Q9. When do I want to use CGI?
Ans: There are innumerable caveats to this solution, however basically any Webpage containing a form will require a CGI script or software to process the shape inputs.
Q10. Can I do HTTP authentication the use of CGI?
Ans: It relies upon on which version of the query you requested.
Yes, we will use CGI to cause the browser's fashionable Username/Password speak. Send a reaction code 401, collectively with a "WWW-authenticate" header together with details of the the authentication scheme and realm: e.G. (in a non-NPH script)
Status: 401 Unauthorized to access the document
WWW-authenticate: Basic realm="foobar"
Unauthorised to get entry to this document
The use you can make of that is server-dependent, and harder,considering that maximum servers assume to deal with authentication earlier than ever attaining the CGI (eg via .Www_acl or .Htaccess).
Thus it cannot usefully replace the same old login collection, although it is able to be applied to different situations, which includes re-validating a user -
e.G after a positive timeout length or if the same individual may also want to login under a couple of userid.
Q11. What you can by no means get in CGI is the credentials returned by the consumer?
Ans: The HTTPD looks after this, and simply units REMOTE_USER to the username if the proper password turned into entered.
Q12. What are the extraordinary instances used in CGI overhead?
CGI overhead is the aggregate of HTTP protocol and it's miles a stateless protocol. CGI needs to be initialized on every occasion it's miles accessed through the browser.
Server is the usage of the fork() to create a brand new technique and then there may be a touch overhead worried in it to maintain on adding the overheads when the approaches grows.
CGI software needs to be initialized earlier than its use. It would possibly involve an overhead in executing a few script.
CGI is an awful lot more concerned with the backend that includes the database that takes extra time to initialize for that reason the overhead ought to no longer be sustained in those cases.
CGI uses scripts which can be inefficient to take the sources and the program that uses machine() or returned tick receives extra overhead then no longer using it.
Q13. What is the feature of CGIWrap in CGI programming?
CGIWrap is used as a gateway software that gives CGI scripts in an HTML bureaucracy layout.
This presents the security of the Http server and allows the consumer to apply the Scripts in a higher and well matched manner.
This allows jogging of the scripts with permissions that may be given with the aid of the users and allows putting up security assessments to perform on the scripts.
This can be accessed using the URL that is being cited in a HTML document and it is configured the use of the consumer scripts.
The scripts are positioned at ~/public_html/cgi-bin/ listing.
Q14. What is the meaning of rigging?
Ans: Rigging is locate for if we want to present animation for any object or individual then we apply to individual or item internal bone placing(like our bones) this is called rigging. When apply rigging, then we can give right animation.
Q15. Can I Identify Users/classes Without Password Protection?
Ans: The most standard (but browser-based) way to do this is to set a cookie. If you do this, you're accepting that no longer all customers could have a 'consultation'.
An opportunity is to pass a consultation ID in every GET URL, and in hidden fields of POST requests. This may be a huge overhead except _every_ web page calls for CGI anyhow.
Another alternative is the Hyper-G solution of encoding a session-id in the URLs of pages lower back:
This has the disadvantage of making the URLs very complicated, and causes any bookmarked pages to generate old session_ids.
Note that a consultation ID based totally completely on REMOTE_HOST (or REMOTE_ADDR) will NOT paintings, as multiple customers may also get admission to your pages simultaneously from the equal system.
Q16. What are the stairs worried in configuring a server the usage of CGI programming?
CGI software can configure the server however, before configuring there are sure parameters that ought to be configured and changed.
Setting of ServerRoot is a ought to if any HTTP server is being used to configure the server.
The directive inside the httpd.Conf have to be pointing to the listing that is at the server and it's miles positioned at /usr/nearby/and so on/httpd.
Then run the CGI scripts which might be being located in ScriptAlias directive as this directive is used to map the sources and its document is srm.Conf.
The directory in which the CGI scripts are placed is as follows:
The user can access the document that he has created via using the subsequent URL on his neighborhood server as:
and the subsequent directory is being finished at the server
/usr/local/and so on/httpd/cgi-bin/howdy
CGI applications have different directories due to the safety reasons and worries. This way all the programs may be set at one area and the server administrator will have the manage over it.
Q17. What does CGI application store?
CGI program shops facts approximately the consumer and it allows the server to look the input string and show the output in keeping with the match.
It consists of the records concerning the host server and the user passing the enter information.
It affords the statistics with the server name, verbal exchange protocol and the name of the software that is running on the system or server.
It includes the directive and listing systems that can be matched at the same time as executing a software or walking a script.
It gives diverse methods to execute the script so that person can understand and the server can execute the enter.
Q18. Can I redirect users to any other page?
Ans: For everlasting and easy redirection, use the HTTPD configuration record:it's miles an awful lot more efficient than doing it your self. Some servers enable you to do this using a file to your very own listing (eg Apache) while others use a unmarried configuration record (eg CERN).
For extra complicated instances (eg procedure shape inputs and conditionally redirect the user), use the "Location:" response header. If the redirection is itself a CGI script, it is straightforward to URLencode
parameters to it in a GET request, but dont neglect to get away the URL!
Ans: require CGI;
$escaped = CGI::break out( $normal );
Sub break out '';
$str =~ s/([^w.-])/sprintf("%%%02X",ord($1))/eg;
$escaped = break out( $regular );
Q20. How can I forestall my CGI script analyzing and writing files as nobody?
Ans: CGI scripts are run by way of the HTTPD, and therefore by using the UID of the HTTPD technique, that is (via convention) commonly a unique consumer "nobody". There are two fundamental methods to run a script below your very own userid:
The direct technique: use a setuid program.
The double-server technique: have your CGI script speak
with a 2nd system (e.G. A daemon) strolling under your userid,that's liable for the real file management.
The direct technique is usually quicker, however the consumer-server structure can also help with different problems, consisting of maintaining integrity of a database.
When walking a compiled CGI program (e.G. C, C++), you may make itsetuid through truely placing the setuid bit: e.G. "chmod 4755 myprog.Cgi"
For safety motives, this isn't always feasible with scripting languages(eg Perl, Tcl, shell). A workaround is to run them from a setuid program, consisting of cgiwrap.
In most cases where you'll want to apply the client-server approach, the server is a completed product (which include an SQL server) with its very own CGI interface.A lightweight opportunity to that is Don Libes' "count on" bundle.