WT Unit 5 NOTES
WT Unit 5 NOTES
PHP Introduction
PHP Engine –
Run Script
?>
Can appear almost everywhere
Externally: include ("myScript.inc")
The included file can have both PHP and XHTML, if the file has PHP, the PHP must be in
<?php .. ?>, even if the include is already in <?php .. ?>
Variable conflict
PHP mode of operation
Copy mode
Interpret mode
Every variable name begin with a $
Case sensitive
A letter or an underscore followed by any number of letters, digits, or underscores.
General Syntactic Characteristics
• Comments - three different kinds (Java and Perl)
// ...
# ...
/* ... */
• Statements are terminated with semicolons
• Compound statements are formed with braces
• Unless used as the body of a function definition, compound
statements cannot be blocks (cannot define locally scoped
variables)
Output
Output from a PHP script is HTML that is sent to the browser
HTML is sent to the browser through standard output
There are three ways to produce output: echo, print, and printf
echo and print take a string, but will coerce other values to strings
$name=“John”; $age=20;
echo “$name“, “$age”; (any number of parameters)
echo(“my name: $name, my age: $age”); (only one)
print “$name and $age";
print (“my name: $name, my age: $age”);
printf(“my name: %s, my age: %s”, $name, $age);
Echo does not return a value; print return 1 or 0; printf returns
the length of the outputted string
PHP Getting Started
PHP 1-27
Primitives, Operations, and Expressions
Strings
Characters are single bytes
The length of a string is limited only by the available memory
String literals use single or double quotes
Single-quoted string literals
Embedded variables are NOT interpolated
Embedded escape sequences are NOT recognized
Double-quoted string literals
Embedded variables ARE interpolated
If there is a variable name in a double quoted string but you don’t want it
interpolated, it must be backslashed
Embedded escape sequences ARE recognized
For both single- and double-quoted literal strings, embedded delimiters
must be backslashed
String character access
$str=“Apple”
$str{2}=“p”
Primitives, Operations, and Expressions
Boolean
values are true and false (case insensitive)
0 and "" and "0" are false; others are true
But “0.0” is true
Arithmetic Operators and Expressions
Usual operators
If the result of integer division is not an integer, a double is returned
Any integer operation that results in overflow produces a double
The modulus operator coerces its operands to integer, if necessary
Arithmetic functions
floor, ceil, round, abs, min, max, rand, etc.
Round($val, x);
Primitives, Operations, and Expressions
Scalar Type Conversions conversion.php
String to numeric
If the string contains an e or an E, it is converted to double; otherwise to
integer
If the string does not begin with a sign or a digit, zero is used
Explicit conversions – casts
e.g., (int)$total or intval($total) or settype($total, "integer")
Intval($total), doubleval($total), strval($total);
The type of a variable can be determined with gettype or
is_type
gettype($total) - it may return "unknown"
is_integer($total) – a predicate function
is_double(), is_bool(), is_string()
PHP
PHP Concatenation
> The concatenation operator (.) is used to put
two string values together.
> To concatenate two string variables together,
use the concatenation operator:
PHP Concatenation
> Arithmetic
> Assignment
> Comparison
> Logical
PHP Operators
PHP Operators
PHP Operators
PHP Operators
Expressions
<?php
$x = "15" + 27;
echo($x);
echo("\n");
?>
PHP Conditional Statements
> Often when you write code, you want the same
block of code to run over and over again in a row.
Instead of adding several almost equal lines in a
script we can use loops to perform a task like this.
> In PHP, we have the following looping
statements:
PHP Functions
> We will now explore how to create your own
functions.
> To keep the script from being executed when
the page loads, you can put it into a function.
> A function will be executed by a call to the
function.
> You may call a function from anywhere within a
page.
PHP Functions
Adding parameters...
> To add more functionality to a function, we can
add parameters. A parameter is just like a
variable.
> Parameters are specified after the function
name, inside the parentheses.
PHP Functions - Parameters
PHP Functions - Parameters
PHP Functions - Parameters
Notice how the URL carries the information after the file name.
PHP Forms - $_GET Function
HTML Forms (GET and POST)
form is submitted to a PHP script
information from that form is
automatically made available to the script
forms.php
<form action="foo.php" method="POST">
Name: <input type="text" name="username"><br>
Email: <input type="text" name="email"><br>
<input type="submit" name="submit" value="Submit
me!">
</form>
Forms – foo.php
<?php
?>
setcookie(“mycookie”);
PHP Sessions
<html>
<body>
</body>
</html>
Session variables
$_SESSION
e.g., $_SESSION[“intVar”] = 10;
Testing if a session variable has been set:
session_start();
if(!$_SESSION['intVar']) {...} //intVar is set or not
Registering session variables
Instead of setting superglobals, one can register one’s own
session variables
<?php
$barney = “A big purple dinosaur.”;
$myvar_name = “barney”;
session_register($myvar_name);
?>
•
$barney can now be accessed “globally” from session to
session
This only works if the register_globals directive is
enabled in php.ini - nowadays this is turned off by default
With session_start() a default session
variable is created - the name extracted
from the page name
To create your own session variable just
add a new key to the $_SESSION
superglobal
$_SESSION[‘dug’]
$_SESSION = “a talking dog.”;
(!isset($_SESSION[$sessionName])) {
$_SESSION[$sessionName] = 0;
print "This is the first time you have visited this page<br/>";
se {
$_SESSION[$sessionName]++;
<body>
<?php
$result = pg_query($db,$query)
or
$rows = pg_num_rows($result);
PostgreSQL Example (cont)
if ($rows > 0) {
printf("Position: %s",$my_row["position“]);
printf(“\n”);
pg_close($db);
?>
</body>
</html>
Wireless Application Protocol
The basic aim of WAP is to provide a web-like
experience on small portable devices - like
mobile phones and PDAs
WAP-Introduction
Purpose of WAP
To enable easy, fast delivery of relevant information
and services to mobile users.
Type of devices that use WAP
Handheld digital wireless devices such as mobile
phones, pagers, two-way radios, smart phones and
communicators -- from low-end to high-end.
Type of OS that use WAP
It can be built on any operating system including Palm
OS, EPOC 32, Windows CE, FLEXOS, OS/9, Java O
Working of Wireless Application
Protocol or WAP Model
WAP Architecture
Wireless MarkupLanguage (WML)
WML is the markup language defined in the WAP
specification. WAP sites are written in WML, while web
sites are written in HTML.
WML is very similar to HTML. Both of them use tags
and are written in plain text format.
WML (Wireless Markup Language), formerly called
HDML (Handheld Devices Markup Languages), is a
language that allows the text portions of Web pages to
be presented on cellular telephones and personal
digital assistants (PDAs) via wireless access
Wireless Markup Language
WML follows a deck and card
A WML document is made up of multiple cards
Cards can be grouped together into a deck
A WML deck is similar to an HTML page
A user navigates with the WML browser through a
series of WML cards.
WMLStructure
< ? xml version=“1.0” ? >
<!DOCTYPE wml …>
<wml>
<card>
<p>
Text….
</p>
<p>
Text……
</p>
</card>
<card>
...
</card>
</wml>
Introduction to ASP.NET
What is ASP.NET and how is different from ASP
ASP: server side technology for creating dynamic web pages
using scripting languages eg vb script.
ASP.NET: server side technology for creating dynamic web
pages using Fully Fledged programming languages
supported by .NET
VB.NET: our chosen language for writing ASP.NET pages
What is .NET?
A Microsoft strategy and new technology for delivering software services
to the desktop and to the web
Components include:
MS Intermediate Language; all code is complied into a more abstract, trimmed
version before execution. All .NET languages are compiled to MSIL – the
common language of .NET
The CLR- common language runtime; responsible for executing MSIL code;
interfaces to Windows and IIS
A rich set of libraries (Framework Class Libraries) available to all .NET
languages
The .NET languages such as C#, VB.NET etc that conform to CLR
ASP.NET is how the Framework is exposed to the web, using IIS to manage
simple pages of code so that they can be complied into full .NET programs.
These generate HTML for the browser.
Built on open protocols (XML, SOAP)
Components
C# VB C++ Compilers
Runtime Environment
Common Type System
Robust And Secure
Native code compilation
MSIL
No interpreter
Install-time or run-time IL to native compilation
Evidence-based security
Policy grants permissions based on evidence (signatures, origin)
.NET Execution Model
VB VC ... Script
Native
IL
Code
Standard JIT
Compiler
Native
Code
Common Language Runtime
Lightweight Just-in-time compiler:
MSIL to Native machine language; Can be ported to numerous platforms
The compiled code is transformed into an intermediate
language called the Microsoft Intermediate Language (MSIL or
IL)
An integer in Visual Basic .NET or an int in C# are converted to
the same .NET data type, which is Int32
The IL that is created is the same for all languages
The assembly is the compiled .NET program
The assembly contains the IL along with additional information
called metadata
Metadata contains information about the assembly
Use the IL Disassembler (ildasm.exe) to view the IL within an
assembly
Framework Overview
VB C++ C# JScript …
Visual Studio.NET
Web Forms
Win Forms
(ASP.NET)
System.Web System.WinForms
Web Services Web Forms Controls Drawing
Mobile controls
Literal controls
Client to Client
- Clients can use XML Web Services to
communicate data
Client to Server
- Clients can send data to and receive
data from servers.
Server to Server
- Servers can share data with each
other.
Service to Service
- web services can work together.
What are the Components of .NET?
.NET Experience
.NET Experiences are XML web services that
allow you to access information across the
internet in an integrated way
Products transitioning into the .NET
experiences are:
MSN Website
Visual Studio .NET Website
Passport Website
.NET Clients
Introduces C#
Web Services Revisited
Web services are platform independent
Encompasses Windows, Unix, Mac, Linux, even PalmOS
Web services are agnostic of the object model being used
Compatible with RPC, DCOM, CORBA, and Sun RMI
Web services are loosely coupled
Unlike tightly-coupled RPC and distributed object systems, which require all the
pieces of an application be deployed at once, you can add clients and servers to
Web-based systems as needed
Web services are built on open standards
XML, SOAP, WSDL, UDDI, HTTP, RPC
Web services are compatible with existing object models
Replaces internal "plumbing" of the network RPC wire format transparently to user
Web services permit secure transmission
HTTPS, SSL
Web Services vs. Traditional Web
Applications
Web services use SOAP messages instead of
MIME messages
Browsers just need to render web pages; web services
need to do more
Web services are not HTTP-specific
SOAP messages can be sent using SMTP, raw TCP or
an instant messaging protocol like Jabber
Web services provide metadata describing the
messages they produce and consume.
XML Schema (XSD) is used to describe various
message structures
Extensible Markup Language
(XML)
XML is the glue that holds .NET together
XML is the defacto standard for data
interoperability.
XML provides a way to put structured data into
a form that can be easily and quickly
transmitted and then interpreted at the other
end
XML looks like HTML, and like HTML, it is
readable and text-based
XML is license-free, platform-independent,
and well supported
Simple Object Access Protocol
(SOAP)
The Envelope is the top-level container representing
the message.
The Header is a generic container for added
features to a SOAP message. SOAP defines
attributes to indicate who should deal with a feature
and whether understanding is optional or
mandatory.
The Body is a container for mandatory information
intended for the ultimate message receiver.
SOAP (cont’d)
Soap is the communications protocol for XML Web services.
SOAP is a specification that defines the XML format for messages—and that's
about it – a SOAP implementation will probably include mechanisms for object
activation and naming services but the SOAP standard doesn't specify them
Optional parts of SOAP specification describe how to represent program data as
XML and how to use SOAP to do Remote Procedure Calls
SOAP is much smaller and simpler to implement than many of the previous
protocols.
DCE and CORBA took years to implement, so only a few implementations were
ever released; SOAP, however, can use existing XML Parsers and HTTP
libraries to do most of the hard work, so a SOAP implementation can be
completed in a matter of months – so several implementations for it have been
released (> 70 to date).
SOAP obviously doesn't do everything that DCE or CORBA do, but the lack of
complexity in exchange for features is what makes SOAP so readily available
Web Service Description Language
(WSDL)
A Web Service Description defines all the supported
methods that a Web Service provides.
WSDL is an XML grammar that developers and
development tools use to represent the capabilities and
syntax of a Web Service.
Similar to IDL for COM and CORBA
Imagine you want to start calling a SOAP method provided
by one of your business partners. WSDL specifies what a
request message must contain and what the response
message will look like in unambiguous notation.
Universal Discovery Description and
Integration (UDDI)
UDDI is the yellow pages of Web Services
you can search for a company that offers the services you need, read about the service
offered and contact someone for more information
A UDDI directory entry is an XML file that describes a business and the services it offers.
There are three parts to an entry in the UDDI directory
"white pages" describe the company offering the service: name, address, contacts, etc.
"yellow pages" include industrial categories based on standard taxonomies such as the North
American Industry Classification System and the Standard Industrial Classification.
"green pages" describe the interface to the service in enough detail for someone to write an
application to use the Web service.
UDDI defines a document format and protocol for searching and retrieving discovery
documents - which in turn link to DISCO documents.
DISCO (Discovery of Web Services) is a Microsoft protocol for retrieving the contracts for
Web Services (WDSL documents).
Web application project files
AssemblyInfo.vb Info about the compiled project file stored
in /bin and named project.dll
Global.asax Event handler commands visible to all web
forms in a project
Global.asax.resx Define application resources such as text
strings, images. Can change without
recompiling project.
Global.asax.vb Asp.net code for application events eg
session.start
Project.sln Stores links to all project files
Project.suo VS.NET IDE configuration info for the proj.
Project.vbproj Configuration and build settings for project
files.
Web application project files cont.
Project.vbproj.webinfo URL to project web server
Project.vsdisco Enables search for web services
Styles.css Project style sheet
Web.config Project and folder configuration information
Webform.aspx Web form .aspx file;Html
Webform.aspx.resx Resources in corresponding web form
Webform.aspx.vb Code written for the form (code behind)
Bin\project.dll Compiled project output file (assembly)
.NET platform
Web-based applications can be distributed to variety of
devices and desktops
C#
Developed specifically for .NET
Enable programmers to migrate from C/C++ and Java easily
Event-driven, fully OO, visual programming language
Has IDE
Process of rapidly creating an application using an IDE is
called Rapid Application Development (RAD)
What Is C#?
C# is type-safe object-oriented language
Enables developers to build a variety of secure and
robust applications
It was developed by Microsoft within the .NET
Framework
C#
Language interoperability
Can interact with software components written in different
languages or with old packaged software written in C/C++
Can interact via internet, using industry standards (SOAP
and XML)
Simple Object Access Protocol - Helps to share program “chunks”
over the internet
Accommodates a new style of programming in which
applications are created from building blocks available
over internet (reusability)
C# and the .NET IDE
Console applications
No visual components
(buttons, text boxes, etc.)
Only text output
Two types
MS-DOS prompt -Used in Windows 95/98/ME
Command prompt -Used in Windows 2000/NT/XP
Features
Very similar in syntax to C, C++, and Java.
Syntax is highly expressive.
Key features: nullable value type,
enumerations, delegates, lambda expressions,
and direct memory access
Advantages
Interoperability
“Interop” process enables C# programs to do
almost anything that a native C++ application can
do.
Ease of Use
Syntax allows for users familiar with C, C++, or
Java to easily start coding in C# very effortlessly.
Advantages (contd)
Reliability
Progression of versions gives the user the feeling of
reliable mature standard.
Support of Community
It approval from the ISO and ECMA as well as
development support from Microsoft give the
standard elite standing.
Applications
C# programs run on the .NET Framework which
is an integral component of Windows that
includes a virtual execution system called
common language runtime (CLR).
Likewise C# programs run on a unified set of
class libraries as well.
Source code relationships
The following diagram
illustrates the compile-
time and run-time
relationships of C#
source code files,
the .NET Framework
class libraries,
assemblies, and the
CLR.
Namespaces
Group related C# features into categories
Contain code that can be reused
.NET framework library (FCL) contains
many namespaces
Must be referenced in order to be used
Example: Console feature is in
namespace System
Methods
Building blocks of C# programs
Every program is a class!
The Main method
Each console or windows application must
have exactly one
Example explained
Using System means that we can use classes from the System
namespace.
namespace is used to organize your code, and it is a container for
classes and other namespaces.
class is a container for data and methods, which brings functionality
to your program.
Another thing that always appear in a C# program, is the Main
method.
Console is a class of the System namespace, which has a
WriteLine() method that is used to output/print text.
● If you omit the using System line, you would have to write
System.Console.WriteLine() to print/output text.
Displaying output