To get your server run CGI scripts properly, you have to configure your Web server. We will discuss how to configure your Apache web server to run CGI scripts. Using ScriptAlias You may set a directory as ScriptAlias Directive (options for configuring Apache). This way, Apache understands that all the files residing within that directory are CGI scripts. This may be the most simple way to r.....
Sometimes, it is desired that you want to give option where a user can click a link and it will pop up a "File Download" dialogue box to the user instead of displaying actual content. This is very easy and can be achieved through HTTP header. For example, if you want make a FileName file downloadable from a given link, then its syntax is as follows − ,
To upload a file, the HTML form must have the enctype attribute set to multipart/form-data. The input tag with the file type creates a "Browse" button. , The result of this code is the following form − , Here is the script save_file.py to handle file upload − , If you run the above script on Unix/Linux, then you need to take care of replacing file separator as follows, otherwise.....
It is very easy to retrieve all the set cookies. Cookies are stored in CGI environment variable HTTP_COOKIE and they will have following form − , Here is an example of how to retrieve cookies. , This produces the following result for the cookies set by above script − ,
It is very easy to send cookies to browser. These cookies are sent along with HTTP Header before to Content-type field. Assuming you want to set UserID and Password as cookies. Setting the cookies is done as follows − , From this example, you must have understood how to set cookies. We use Set-Cookie HTTP header to set cookies. It is optional to set cookies attributes like Expires, Do.....
HTTP protocol is a stateless protocol. For a commercial website, it is required to maintain session information among different pages. For example, one user registration ends after completing many pages. How to maintain user's session information across all the web pages? In many situations, using cookies is the most efficient method of remembering and tracking preferences, purchases, commi.....
You must have come across many situations when you need to pass some information from your browser to web server and ultimately to your CGI Program. Most frequently, browser uses two methods two pass this information to web server. These methods are GET Method and POST Method. Passing Information using GET method The GET method sends the encoded user information appended to the page request.....
CGI Environment Variables All the CGI programs have access to the following environment variables. These variables play an important role while writing any CGI program. Sr.No. Variable Name Description1CONTENT_TYPEThe data type of the content. Used when the client is sending attached content to the server. For example, file upload.2CONTENT_LENGTHThe length of the query in.....
The line Content-type:text/html\r\n\r\n is part of HTTP header which is sent to the browser to understand the content. All the HTTP header will be in the following form − HTTP Field Name: Field Content For Example Content-type: text/html\r\n\r\n There are few other important HTTP headers, which we will use frequently in our CGI Programming. Sr.No.HeaderDescription1.....
If we run simple scripts like hello.py, its output is written on the STDOUT file, i.e., screen. There is one important and extra feature available which is the first line to be printed Content-type:text/html\r\n\r\n. This line is sent back to the browser and it specifies the content type to be displayed on the browser screen. We can write advanced CGI programs using Python. This scrip.....
Sign up now to get your own personalized profile!
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more