Rajendra Dharmkar has Published 784 Answers

How to configure Apache for Python CGI Programming?

Rajendra Dharmkar
Published on 31-Jan-2018 10:10:35
Configure Apache Web server for CGITo 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 ScriptAliasYou may set a directory as ScriptAlias Directive (options for configuring Apache). This way, Apache understands ... Read More

How to raise a "File Download" Dialog Box in Python CGI Programming?

Rajendra Dharmkar
Published on 31-Jan-2018 10:04:34
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 ... Read More

How do we do a file upload using Python CGI Programming?

Rajendra Dharmkar
Published on 31-Jan-2018 08:30:30
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.Example<html> <body>    <form enctype = "multipart/form-data"                      action = "save_file.py" method = "post">    <p>File: ... Read More

How to retrieve cookies in Python CGI Programming?

Rajendra Dharmkar
Published on 31-Jan-2018 08:22:11
Retrieving CookiesIt is very easy to retrieve all the set cookies. Cookies are stored in CGI environment variable HTTP_COOKIE and they will have following form −key1 = value1;key2 = value2;key3 = value3....Here is an example of how to retrieve cookies.#!/usr/bin/python # Import modules for CGI handling from os import environ ... Read More

How to setup cookies in Python CGI Programming?

Rajendra Dharmkar
Published on 31-Jan-2018 08:19:55
Setting up CookiesIt 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 −#!/usr/bin/python print "Set-Cookie:UserID = XYZ;\r\n" print "Set-Cookie:Password = XYZ123;\r\n" print ... Read More

How do cookies work in Python CGI Programming?

Rajendra Dharmkar
Published on 31-Jan-2018 08:18:23
Using Cookies in CGIHTTP 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 ... Read More

What is the difference between GET and POST in Python CGI Programming?

Rajendra Dharmkar
Published on 31-Jan-2018 08:15:40
GET and POST MethodsYou 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 ... Read More

What are environment variables available in Python CGI Programming?

Rajendra Dharmkar
Published on 31-Jan-2018 07:59:05
CGI Environment VariablesAll 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 ... Read More

What are important HTTP headers to be frequently used in Python CGI Programming?

Rajendra Dharmkar
Published on 31-Jan-2018 07:34:43
HTTP HeaderThe 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 ContentFor ExampleContent-type − text/html\r\n\r\nThere are few other important HTTP headers, which we will use frequently in ... Read More

What Content-type is required to write Python CGI program?

Rajendra Dharmkar
Published on 31-Jan-2018 07:26:04
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 ... Read More
1 2 3 4 5 6 7 ... 79 Next
Advertisements