YouTube Icon

Interview Questions.

Cgi Programming Placement Papers - Cgi Programming Interview Questions and Answers - Jul 28, 2022

fluid

Cgi Programming Placement Papers - Cgi Programming Interview Questions and Answers

Q1. What Is Cgi?

CGI stands for Common Gateway Interface, and is a mechanism via which a browser is permitted to communicate with programs going for walks on a server. If you have a look at each word in turn it makes greater experience -

Common - some thing that is available to many humans, regardless of what software they may be the use of.

Gateway - a portal through which  matters communicate. In this situation, the browser communicates to the server.

Interface - this means that we are imparting a "the front give up" for the software running at the server, which is exactly what it's miles. You enter facts inside the form, for example, and this is submitted to the program, similar to a home windows-style application.

Q2. What Is The Difference Between A Cgi Script And A Cgi Program?

Generally, scripts are best numerous lines of code which do some useful function that would be overkill to put in writing in a complete-featured language. With Perl, you could cross both way. You can write Perl scripts and Perl programs. Larry Wall (the author of Perl) as soon as stated "You can write Perl packages, and you can write C scripts. More humans communicate approximately Perl programs than C scripts, so I wager that me Perl is greater flexible".

Q3. What Is The Difference Between Object Oriented And Structured Oriented Programming?

Object Oriented me programme could be their in phrases of Class and Object relationship may be their.

Structured Oriented Me programme might be their in terms of a couple of Functions.

Q4. Can I Identify Users/periods Without Password Protection?

The most common (but browser-established) manner to do that is to set a cookie. If you try this, you are accepting that not all users could have a 'consultation'.

An opportunity is to skip a session ID in every GET URL, and in hidden fields of POST requests. This can be a massive overhead until _every_ page calls for CGI in any case.

Another alternative is the Hyper-G[1] solution of encoding a consultation-id in the URLs of pages returned:

http://hyper-g.Server/session_id/real/course/to/page

This has the downside of making the URLs very difficult, and causes any bookmarked pages to generate antique session_ids.

Note that a session ID primarily based totally on REMOTE_HOST (or REMOTE_ADDR) will NOT work, as a couple of customers may access your pages simultaneously from the equal machine.

Q5. Are There Some Interactive Debugging Tools And Services Available?

Several CGI programming libraries provide powerful interactive debugging centers. These consist of:

- for Perl, Lincoln Stein's CGI.Pm

(now part of the same old Perl distribution)

- for Tcl, Don Libes' cgi.Tcl

http://count on.Nist.Gov/cgi.Tcl

- for C++, Nick Kew's CGI++

http://www.Webthing.Com/cgiplusplus/

Nathan Neulinger's cgiwrap is another package deal with debugging aids.

The "mod_cgi" Apache module (new with Apache 1.2) permits you to seize script output and mistakes for analysis.

Q6. Is It Possible To Set A Cookie And Then Redirect A Return Visitor To A Different Url All Using Cgi?

Try:

#! /usr/bin/perl -w

use CGI qw(:cgi);

my $q = CGI->new();

my $cookie = $q->cookie(

-call => 'yummy_cookie',

-cost => 'chocolate chip',

-domain => '.Globalguideline.Com',

-expires => '+10d',

-route => '/'

);

print $q->redirect(

-url => 'http://www.Globalguideline.Com',

-cookie => $cookie

);

__END__

If you omit the "-area", and "-direction", then they'll default to present day values. The above instance might be again to all servers in the irt.Org area.

If you omit the "-expires", then the cookie will expire when the user closes their browser. The above expires after 10 days.

Q7. Does Cgi Create New Security Risks?

Yes. Period.

There is lots you may do to minimize these.

Q8. What Is A Cgi Bin Directory?

A CGI bin directory is a special directory on the server in which CGI scripts are allowed to be completed.

Most servers are configured to only allow CGI scripts to be completed from one location, so that it will decrease protection holes. Poorly written scripts can wreak havoc on a server if allowed to run unchecked - most gadget admins will want to affirm that the script isn't doing whatever malicious earlier than letting you run it.

Q9. What Is Perl?

Perl is an interpreted language (not compiled, like Java) that's perfectly suited for CGI programming. It has its roots in Unix gadget administration and gives numerous features like regular expressions and document manipulation which make it extraordinarily effective. It is gaining knowledge of curve has been defined as lengthy and shallow.

It is very easy to choose up in the beginning, in particular in case you are in any respect acquainted with Unix. However, it does take quite a bit of time to come to be acquainted with all the little nuances of the language.

Q10. What Is Difference Between Cgi And Java?

CGI and JAVA are essentially distinctive, and for most packages are NOT interchangable.

CGI is a protocol for jogging applications on a WWW server. Whilst JAVA also can be used for that, and even has a standardised API (the servlet, that is certainly an opportunity to CGI), the predominant function of JAVA on the Web is for clientside programming (the applet).

In sure times the 2 may be combined in a unmarried software:

for example a JAVA applet to define a region of hobby from a geographical map, collectively with a CGI script to procedure a question for the location described.

Q11. Explain Is Cgi A Script Or A Program?

The distinction is semantic.Traditionally, compiled executables(binaries) are known as packages, and interpreted programs are normally referred to as scripts.In the context of CGI,the difference has emerge as even greater blurred than before.The words are regularly used interchangably (which includes on this document).Current usage favours the phrase "scripts" for CGI packages.

Q12. Do I Need To Be On Unix?

No, however it facilitates. The Web, along side the Internet itself, C, Perl, and almost every other Good Thing within the closing twenty years of computing, originated in Unix. At the time of writing, this is nevertheless the most mature and excellent-supported platform for Web programs.

Q13. Why Should I Use Cgi?

CGI is essential on every occasion you need to hold country facts approximately a consumer, or run an utility which communicates with the server. Things like guestbooks, Chat customers, database programs, and counters all rely on CGI. CGi opens up a international of possibility and permits you to do matters that just aren't viable with a totally patron-aspect approach like JavaScript.

Q14. What Do I Absolutely Need To Know In Cgi?

If you are already a programmer,CGI is extraordinarily trustworthy, and just three sources ought to get you on top of things within the time it takes to examine them:

Installation notes in your HTTPD.Is it configured to run CGI scripts, and if so how does it identify that a URL should be carried out? (Check your manuals, READMEs, ISP webpages/FAQS, and if you still cannot locate it ask your server administrator).

The CGI specification at NCSA tells you all you want to recognise to get your applications going for walks as CGI packages.

WWW Security FAQ. This isn't always required to 'get it operating', however is important studying if you want to KEEP it working!

If you are NOT already a programmer, you'll ought to learn. If you'll discover it difficult to write down, say, a 'grep' or 'cat' utility to run from the commandline, then you will in all likelihood have a hard time with CGI. Make sure your applications work from the commandline BEFORE trying them with CGI, so that as a minimum one possible source of mistakes has been treated.

Q15. What Is The Difference Between An Interpreted Language And A Compiled Language?

A compiled language is written and then run via a compiler which checks its syntax and compresses it right into a binary executable. Since an interpreted language is not compiled, it ought to be checked for errors at run-time, which makes it pretty a piece 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 necessarily suggest it is not full-featured, or simplistic. Perl can get very complicated and really cryptic, in no time.

Q16. Is There An Equivalent Of Javascripts Escape() Function In Perl?

Try This:

require CGI;

$escaped = CGI::escape( $regular );

# ...Or...

Sub get away 

$escaped = break out( $normal );

Q17. Should I Use Cgi Or An Api?

APIs are proprietary programming interfaces supported by means of specific structures. By the usage of an API, you lose all portability. If you recognize your utility will handiest ever run on one platform (OS and HTTPD), and it has a suitable API, move ahead and use it. Otherwise keep on with CGI.

Q18. When Do I Need To Use Cgi?

There are innumerable caveats to this wer, but essentially any Webpage containing a shape will require a CGI script or software to technique the shape inputs.

Q19. How Can I Run My Cgi Program Live In A Debugger?

At First,within the CGI code, at it's far begin, upload "sleep(30);". This will reason the CGI to do not anything for thiry seconds (you can need to modify this time). Compile the CGI with debuging data ("-g" in gcc) and installation the CGI as regular. Next, the usage of your net browser, activate the CGI. It will of path simply sit down there doing not anything.

While it is slumbering, find it is PID(playstation  grep <cgi name>). Load your debugger and fasten to that PID("connect <pid>" in gdb). You can even need to tell it in which to discover the symbol definitions ("image-file <cgi>" in gdb).

Then set a ruin point after the invocation of the sleep feature and you're prepared to debug. Do be conscious that your browser will in the end timeout if it does no longer get hold of whatever.

Q20. Is It A Script Or A Program?

The distinction is semantic. Traditionally, compiled executables (binaries) are known as packages, and interpreted programs are normally called scripts. In the context of CGI, the difference has become even more blurred than earlier than. The words are regularly used interchangably (inclusive of on this document). Current utilization favours the phrase "scripts" for CGI applications.

Q21. Do I Have To Use Perl?

No - you can use any programming language you please. Perl is sincerely trendy most popular choice for CGI programs. Some different widelyused languages are C, C++, TCL, BASIC and - for simple tasks -even shell scripts.

Q22. Can I Run A Cgi Script Without Returning A New Page To The Browser?

Yes, but assume carefully first: How are your readers going to recognise that their "post" has succeeded? They may additionally hit 'post' regularly!

The accurate answer in keeping with the HTTP specification is to go back HTTP fame code 2@As an NPH script, this would be:

#!/bin/sh

# do processing (or launch it as historical past task)

echo "HTTP/1.Zero 204 No Change"

echo

Q23. Can I Redirect Users To Another Page?

For everlasting and easy redirection, use the HTTPD configuration record:

it is an awful lot greater green than doing it your self. Some servers allow you to do that the usage of a report to your very own directory (eg Apache) whereas others use a unmarried configuration document (eg CERN).

For extra complicated cases (eg manner form 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, however dont forget to break out the URL!

Q24. How Can I Stop My Cgi Script Reading And Writing Files As Nobody?

CGI scripts are run by means of the HTTPD, and therefore through the UID of the HTTPD process, that is (by using conference) typically a special user "no one".

There are  fundamental approaches to run a script under your own userid:

(1) The direct method: use a setuid program.

(2) The double-server technique: have your CGI script communicate with a 2nd technique (e.G. A daemon) going for walks underneath your userid, which is accountable for the actual report control.

The direct method is generally quicker, but the customer-server structure may also assist with different issues, which includes keeping integrity of a database.

When running a compiled CGI software (e.G. C, C++), you could make it setuid by using actually setting the setuid bit:

e.G. "chmod 4755 myprog.Cgi"

For security motives, this is not viable with scripting languages (eg Perl, Tcl, shell). A workaround is to run them from a setuid program, inclusive of cgiwrap.

In maximum instances in which you'd want to apply the customer-server method, the server is a finished product (such as an SQL server) with its very own CGI interface.

A light-weight alternative to this is Don Libes' "count on" bundle.




CFG