Unit 1 Web Computing
Unit 1 Web Computing
o Hypertext Transfer Protocol is a set of rule which is used for transferring the
files like, audio, video, graphic image, text and other multimedia files on the
WWW (World Wide Web).
o The standard (default) port for HTTP connection is 80, but other port can also
be used.
o The first version of HTTP was HTTP/0.9, which was introduced in 1991.
o The latest version of HTTP is HTTP/3, which was published in September 2019.
It is an alternative to its processor HTTP/2.
o This latest version is already in use on the web with the help of UDP (User
Datagram Protocol) instead of TCP (Transmission Control Protocol) for the
underlying transport protocol.
o HTTP is a protocol that is used to transfer the hypertext from the client end to
the server end, but HTTP does not have any security.
o Whenever a user opens their Web Browser, that means the user indirectly uses
HTTP.
Stateless: The HTTP is stateless. The client and server just know about each other
just during the current request. If the connection is closed, and two computers
want to connect again, they need to provide information to each other anew, and
the connection is handled as the very first one.
HTTP Needs
o The HTTP was designed mainly to fetch the html document and send it to the
client. That all the HTTP was doing in 1991, and it did not support other media
types, it just delivers html document.
Prerequisite
Before learning HTTP, you must have the basic knowledge of web concepts,
web browsers, web servers, client and server architecture based software.
Audience
Our HTTP tutorial is designed to help beginners and professionals both.
Problems
We assure you that you will not find any difficulty while learning HTTP tutorial.
But, if you find any type of mistake, then you can post it in our comment
section.
Parameters of HTTP
In this section, we will discuss various HTTP parameters and their syntax. For
example, date and time format, character set, etc. These parameters are used
in the construction of our request and response message while writing the
HTTP program of the client or server.
The first line in the HTTP-Version field indicates the version of the HTTP
message.
Syntax
Entity Tags
Entity tags are used to compare two or more entities from the same requested
resource.
Syntax
2. weak = "W/"
3. opaque-tag = quoted-string
4. An Entity tag must be unique across all the entity versions associated
with a particular resource.
Web Browser and Web Server.
The terms web browser and web server are very common in the field of
computer science and Internet, however people often get confused
between the two. The most basic difference between a web browser and a
web server is that a web browser is an application software which is used
to browse and display webpages available over the Internet, whereas
a web server is a software hosted on a dedicated computer which provides
these documents when requested by web browsers.
What is a Web Browser?
A web browser is an application software that can process and display a web page
on the internet. The web browser is capable to make a request for web services
and documents to web server. It acts an interface between the server and the
client. As web browser is a software, thus it is to be installed on the client
computer and used to surf the internet for websites and web pages. Popular
examples of web browsers include Google Chrome, Microsoft Internet Explorer,
Microsoft Edge, Mozilla Firefox, Opera Mini, etc.
A web server is a dedicated computer that sends web based documents to the
client’s computer when request through the web browser. A web server accepts
HTTP request from the client’s browser, processes it to find the required
document, and then sends a suitable response to client machine.
A web server is a basically a set of hardware and software whose primary function
is to serve web-based material through the internet on demand.
What is PHP
PHP is an open-source, interpreted, and object-oriented scripting language
that can be executed at the server-side. PHP is well suited for web
development. Therefore, it is used to develop web applications (an application
that executes on the server and generates the dynamic page.).
PHP was created by Rasmus Lerdorf in 1994 but appeared in the market in
1995. PHP 7.4.0 is the latest version of PHP, which was released on 28
November. Some important points need to be noticed about PHP are as
followed:
o PHP stands for Hypertext Preprocessor.
o PHP is faster than other scripting languages, for example, ASP and JSP.
o PHP supports several protocols such as HTTP, POP3, SNMP, LDAP, IMAP, and
many more.
o Using PHP language, you can control the user to access some pages of your
website.
o As PHP is easy to install and set up, this is the main reason why PHP is the
best language to learn.
o PHP can handle the forms, such as - collect the data from users using forms,
save it into the database, and return useful information to the user. For
example - Registration form.
PHP Features
PHP is very popular language because of its simplicity and open source. There are
some important features of PHP given below:
Performance:
PHP script is executed much faster than those scripts which are written in
other languages such as JSP and ASP. PHP uses its own memory, so the server
workload and loading time is automatically reduced, which results in faster
processing speed and better performance.
Open Source:
PHP source code and software are freely available on the web. You can develop
all the versions of PHP according to your requirement without paying any cost.
All its components are free to download and use.
Embedded:
PHP code can be easily embedded within HTML tags and script.
Platform Independent:
PHP is available for WINDOWS, MAC, LINUX & UNIX operating system. A PHP
application developed in one OS can be easily executed in other OS also.
Database Support:
PHP supports all the leading databases such as MySQL, SQLite, ODBC, etc.
Error Reporting -
PHP allows us to use a variable without declaring its datatype. It will be taken
automatically at the time of execution based on the type of data it contains
on its value.
PHP is compatible with almost all local servers used today like Apache,
Netscape, Microsoft IIS, etc.
Security:
Control:
White Space
White space can contain the characters for tabs, blanks, newlines, and form
feeds. These characters are ignored except when they serve to separate other
tokens. However, blanks and tabs are significant in strings.
Comments
There are two types to represent the comments, such as:
1. Single line comments begin with the token // and end with a carriage return.
For example, //this is the single-line syntax.
2. Multi-Line comments begin with the token /* and end with the token */
For example, /* this is multiline syntax*
What is a variable?
Reference Variables
A reference variable is a variable that points to an object of a given class,
letting you access the value of an object. An object is a compound data
structure that holds values that you can manipulate. A reference variable does
not store its own values. Instead, when you reference the reference variable,
OpenROAD uses the values in the corresponding object. The object is made
up of attributes, which can be simple variables, reference variables, or array
variables.
The class of an object defines its attributes. OpenROAD includes both system
classes and user-defined classes.
In your 4GL code, when you reference a reference variable, you can work with
the entire object as a single unit. For example, you can retrieve a row from a
database table and assign all values from the row to a single object and then
pass the object to a called procedure.
The value of class can be any named user class or system class (for a
complete list of system classes, see the Language Reference Guide online
help). The following example declares a reference variable of the StringObject
class:
strobj = StringObject;
For example, assume that the subform previously described contained a field
called Address. To reference that field, you would use:
customer.Address
In the following example, City and Street are attributes of class addr, and
address is a declared reference variable:
address.City = 'Dallas';
x = address.Street;
callframe delete_old (address = address.City);
OpenROAD checks references to attributes by name and produces compiler
errors if the variable's class does not contain those attributes. For example,
given the following declarations:
a = Addr;
b = Addr;
tmp_char = varchar(30) not null;
a = null;
a.Street = tmp_char; /* ERROR at runtime because 'a' is
** null, and does not reference
** an object */
As an alternative, you can specify default null on the declaration and a default
object is not created.
You can check for a null reference variable with the is null operator, for
example:
if a is null then
/* processing statements */
endif;
For more information about null reference variables, see Nulls in Expressions.
For more information about the Create method, see the Class class Create
Method. Examples of using the Create method are provided in "Creating a
Frame at Runtime" in the Programming Guide.
• Global Variables − A global variable has global scope which means it can be defined
anywhere in your JavaScript code.
• Local Variables − A local variable will be visible only within a function where it is
defined. Function parameters are always local to that function.
Within the body of a function, a local variable takes precedence over a global
variable with the same name. If you declare a local variable or function parameter
with the same name as a global variable, you effectively hide the global variable.
int a = 1;
string s = "cat";
In lexical analysis, literals of a given type are generally a token type, with a grammar
rule, like "a string of digits" for an integer literal. Some literals are specific keywords,
like true for the boolean literal "true".
In some object-oriented languages (like ECMAScript), objects can also be represented by
literals. Methods of this object can be specified in the object literal using function
literals. The brace notation below, which is also used for array literals, is typical for
object literals:
{"cat", "dog"}
{name: "cat", length: 57}
Type Casting:
In typing casting, a data type is converted into another data type by the
programmer using the casting operator during the program design. In typing
casting, the destination data type may be smaller than the source data type
when converting the data type to another data type, that’s why it is also called
narrowing conversion.
Syntax/Declaration:-
destination_datatype = (target_datatype)variable;
(): is a casting operator.
target_datatype: is a data type in which we want to convert the source data
type.
Type Juggling
Type juggling also takes place during calculation of expression. In this example,
a string variable containing digits is automatically converted to integer for
evaluation of addition expression.
Example
<?php
$var1=100;
$var2="100 days";
$var3=$var1+var2;
var_dump($var3);
?>
Output
Type casting forces a variable to be used as a certain type. Following script shows
example of different type cast operators.
Literals are defined as a value that is written in the source code, for example, a
number, a string, Boolean or also more advanced constructs, like Object Literals
or Array Literals:
10
‘Vikuman’
true
[‘Apple’, ‘Banana’]
{name: ‘Vikas’, age: ‘24’}
• Boolean
• Integer
• Double
• String
• Array
• Objects
• NULL
• resource
The first five are called simple data types and the last three are compound
data types:
String: Hold letters or any alphabets, even numbers are included. These
are written within double quotes during declaration. The strings can also
be written within single quotes, but they will be treated differently while
printing variables. To clarify this look at the example below.
Boolean: Boolean data types are used in conditional testing. Hold only
two values, either TRUE(1) or FALSE(0). Successful events will
return true and unsuccessful events return false. NULL type values are
also treated as false in Boolean. Apart from NULL, 0 is also considered
false in boolean. If a string is empty then it is also considered false in
boolean data type.
Array: Array is a compound data type that can store multiple values of
the same data type. Below is an example of an array of integers. It
combines a series of data that are related together.
NULL: These are special types of variables that can hold only one value
i.e., NULL. We follow the convention of writing it in capital form, but it’s
case-sensitive. If a variable is created without a value or no value, it is
automatically assigned a value of NULL. It is written in capital letters.
Resources: Resources in PHP are not an exact data type. These are
basically used to store references to some function call or to external PHP
resources. For example, consider a database call. This is an external
resource. Resource variables hold special handles for files and database
connections.
We will discuss resources in detail in further articles.
Please log in. Because if is a statement, you can chain them: if ($good)
print('Dandy!'); else if ($error) print('Oh, no!'); else print("I'm ambivalent...");
Such chains of if statements are common enough that PHP provides an easier
syntax: the elseif statement. For example, the previous code can be rewritten
as: if ($good) print('Dandy!'); elseif ($error) print('Oh, no!'); else print("I'm
ambivalent..."); The ternary conditional operator (?:) can be used to shorten
simple true/false tests. Take a common situation such as checking to see if a
given variable is true and printing something if it is. With a normal if/else
statement, it looks like this: With the ternary conditional operator, it looks like
this: '.($active ? 'yes':'no').'' ?> Compare the syntax of the two: if (expression)
true_statement else false_statement (expression) ? true_expression :
false_expression The main difference here is that the conditional operator is not
a statement at all. This means that it is used on expressions, and the result of a
complete ternary expression is itself an expression. In the previous example, the
echo statement is inside the if condition, while when used with the ternary
operator, it precedes the expression.
Switch:
switch It often is the case that the value of a single variable may determine one
of a number of different choices (e.g., the variable holds the username and you
want to do something different for each user). The switch statement is designed
for just this situation. A switch statement is given an expression and compares
its value to all cases in the switch; all statements in a matching case are
executed, up to the first break keyword it finds. If none match, and a default is
given, all statements following the default keyword are executed, up to the first
break keyword encountered. For example, suppose you have the following: if
($name == 'ktatroe') // do something elseif ($name == 'rasmus') // do something
elseif ($name == 'ricm') // do something elseif ($name == 'bobk') // do
something You can replace that statement with the following switch statement:
switch($name) { case 'ktatroe': // do something break; case 'rasmus': // do
something break; case 'ricm': // do something break; case 'bobk': // do
something break; } The alternative syntax for this is: switch($name): case
'ktatroe': // do something break; case 'rasmus': // do something break; case
'ricm': // do something break; case 'bobk': // do something break; endswitch;
Because statements are executed from the matching case label to the next
break keyword, you can combine several cases in a fall-through. In the following
example, "yes" is printed when $name is equal to "sylvie" or to "bruno": switch
($name) { case 'sylvie': // fall-through case 'bruno': print('yes'); break; default:
print('no'); break; } Commenting the fact that you are using a fall-through case
in a switch is a good idea, so someone doesn't come along at some point and
add a break, thinking you had forgotten it. You can specify an optional number
of levels for the break keyword to break out of. In this way, a break statement
can break out of several levels of nested switch statements. An example of using
break in this manner is shown in the next section.
For:
The for statement is similar to the while statement, except it adds counter
initialization and counter manipulation expressions, and is often shorter and
easier to read than the equivalent while loop. Here's a while loop that counts
from 0 to 9, printing each number: $counter = 0; while ($counter < 10) { echo
"Counter is $counter\n"; $counter++; } Here's the corresponding, more concise
for loop: for ($counter = 0; $counter < 10; $counter++) echo "Counter is
$counter\n"; The structure of a for statement is: for (start; condition; increment)
statement The expression start is evaluated once, at the beginning of the for
statement. Each time through the loop, the expression condition is tested. If it
is true, the body of the loop is executed; if it is false, the loop ends. The
expression increment is evaluated after the loop body runs. The alternative
syntax of a for statement is: for (expr1; expr2; expr3): statement; ...; endfor; This
program adds the numbers from 1 to 10 using a for loop: $total = 0; for ($i= 1;
$i <= 10; $i++) { $total += $i; } Here's the same loop using the alternate syntax:
$total = 0; for ($i = 1; $i <= 10; $i++): $total += $i; endfor; You can specify multiple
expressions for any of the expressions in a for statement by separating the
expressions with commas. For example: $total = 0; for ($i = 0, $j = 0; $i <= 10;
$i++, $j *= 2) { $total += $j; } You can also leave an expression empty, signaling
that nothing should be done for that phase. In the most degenerate form, the
for statement becomes an infinite loop. You probably don't want to run this
example, as it never stops printing: for (;;) { echo "Can't stop me!
"; } In for loops, as in while loops, you can use the break and continue keywords
to end the loop or the current iteration.
Foreach:
The foreach statement allows you to iterate over elements in an array. The two
forms of foreach statement are discussed in Chapter 5. To loop over an array,
accessing each key, use: foreach ($array as $current) { // ... } The alternate syntax
is: foreach ($array as $current): // ... endforeach; To loop over an array,
accessing both key and value, use: foreach ($array as $key => $value) { // ... }
The alternate syntax is: foreach ($array as $key => $value): // ... endforeach;
Declare:
The declare statement allows you to specify execution directives for a block of
code. The structure of a declare statement is: declare (directive) statement
Currently, there is only one declare form, the ticks directive. Using it, you can
specify how frequently (measured roughly in number of code statements) a tick
function registered with register_tick_function( ) is called. For
The exit statement ends execution of the script as soon as it is reached. The return
statement returns from a function or (at the top level of the program) from the script.
The exit statement takes an optional value. If this is a number, it's the exit status of the
process. If it's a string, the value is printed before the process terminates. The exit( )
construct is an alias for die( ): $handle = @mysql_connect("localhost", $USERNAME,
$PASSWORD); if (!$handle) { die("Could not connect to database"); } This is more
commonly written as: $handle = @mysql_connect("localhost", $USERNAME,
$PASSWORD) or die("Could not connect to database");