SlideShare a Scribd company logo
1 of 63
Download to read offline
1 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
Introduction to Object Oriented Programming in PHP
Class
1.It is blueprint of the object
2.The class contains the methods &properties
Object
It is instance of class
<?php
class phpClass
{
var $var1;
var $var2 = "constant string";
function myfunc ($arg1, $arg2)
{
}
……
……
}
?>
<?php
class student
{
var $rollno;
var $name;
function accept()
{
$this-> rollno=1;
$this->name="amol";
}
function display()
{
2 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
echo "Rollno ".$this->rollno;
echo "Name ".$this->name;
}
}
$s1=new student;
$s1->accept();
$s1->display();
?>
Note:
• Variable declarations start with the special form var, which is followed by a conventional
$ variable name.
• -> is used to access properties & method of class.
Use of this keyword:
The $this is a keyword which represents the current object or current instance of class. $this is a
special self-referencing variable that is used to access properties and methods from within the
class.
Constructor
Constructor Functions are special type of functions which are called automatically whenever an
object is created.
PHP provides a special function called __construct() to define a constructor.
Syntax
function __connstruct(arglist)
{
}
3 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
Destructor
Destructor function is called when an object is destroyed
It can define a destructor function using function __destruct()
Syntax
function __destruct()
{
}
<?php
class student
{
var $rollno;
var $name;
function __construct($a,$b)
{
$this-> rollno=$a;
$this->name=$b;
}
function display()
{
echo "Rollno ".$this->rollno;
echo "Name ".$this->name;
}
function __destruct()
{
echo "destory";
}
}
4 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
$s1=new student(1,"amol");
$s1->display();
?>
Visibility
Public member:It can access a public method or property from inside or outside the class.
Private member: It can access a private method or property only inside the class.
Protected member: It can access a protected method or property available to class itself and to
classes that inherited from it.
Introspection
Introspection is the ability of a program to examine an object's characteristics, such as its
name, parent class (if any), properties, and methods
Examine Classes
Syntax Description
class_exists(classname) This function returns true if classname is a
defined otherwise false
get_declared_classes() This function returns array of defined class
get_class_methods(classname) This function return array of class method
name
get_class_vars(classname) This function return an array of default
properties of the class
get_parent_class(classname) It return name of parent class
<?php
class student
{
var $rollno;
var $name;
5 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
function display()
{
echo "Rollno ".$this->rollno;
echo "Name ".$this->name;
}
}
$m=new student();
$a=class_exists('student');
echo "$a";
$b=get_declared_classes();
print_r($b);
$c=get_class_vars('student');
print_r ($c);
$d=get_class_methods('student');
print_r($d);
echo is_object($m);
echo get_class($m);
print_r(get_object_vars($m));
?>
Examine Methods
Syntax Description
is_object(object) It return true if passed parameter is an object
get_class(object) It return name of the class of an object
get_object_vars(object) Gets the properties of the given object
Inheritance
PHP support inheritance concept.In a inheritance, the new class can inherit the properties and
methods from old class.The old class is called base class or super class & new class is called
derived class.
The “extends” keyword is used for the inheritance.
<?php
class student
{
var $name;
}
class result extends student
6 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
{
var $grade;
function accept()
{
$this->name="amol";
$this-> grade="A";
}
function display()
{
echo "Rollno ".$this->name;
echo "Grade ".$this->grade;
}
}
$s1=new result;
$s1->accept();
$s1->display();
?>
Serialization
Serailizing object means converting into byte representation that can be stored into a file.
It can done using two function
1 serialize():It return a string containing a byte stream representation of any value that can be
stored in PHP.
String serialize(mixed $val)
2 unserialize():To turn back the serialized string into php variables.
Mixed unserialize(String $val)
<?php
class student
{
var $rollno;
var $name;
7 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
function accept()
{
$this-> rollno=1;
$this->name="amol";
}
function display()
{
echo "Rollno ".$this->rollno;
echo "Name ".$this->name;
}
}
$s1=new student;
$s1->accept();
$ob=serialize($s1);
$fp=fopen("c:a1.txt","w");
fwrite($fp,$ob);
fclose($fp);
$rob=unserialize($ob);
$rob->display();
?>
__sleep and __wakeup function
This function are used to notify objects that are being serialized or unsterilized
serialize() checks if your class has a function with the magic name __sleep. If so, that function is
being run prior to any serialization. It can clean up the object and is supposed to return an array
with the names of all variables of that object that should be serialized. If the method doesn't
return anything then NULL is serialized and E_NOTICE is issued.
unserialize() checks for the presence of a function with the magic name __wakeup. If present,
this function can reconstruct any resources that object may have.
<?php
class student
{
var $rollno;
8 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
var $name;
function accept()
{
$this-> rollno=1;
$this->name="amol";
}
public function __sleep()
{
echo "sleep calling<br>";
return array('rollno','name');
}
function __wakeup()
{
echo "Waking up...";
}
}
$s1=new student;
$s1->accept();
$ob=serialize($s1);
echo "$ob";
$rob=unserialize($ob);
print_r($rob);
?>
Method overriding
The same method (same prototype) of base class overrides in their derived class known as
method overriding
<?php
class base
{
function display()
{
echo "base class<br>";
9 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
}
}
class derived extends base
{
function display()
{
parent::display();
echo "derived class<br>";
}
}
$s1=new derived;
$s1->display();
?>
Abstract Class
An abstract class is a class that is declared abstract—it may or may not include abstract
methods. Abstract classes cannot be instantiated, but they can be subclassed.
abstract method:A method that is declared as abstract and does not have implementation (no
body)is known as abstract method
<?php
abstract class A
{
abstract function display();
}
class B extends A
{
function display()
{
echo "derived class<br>";
}
}
$s1=new B();
$s1->display();
10 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
?>
Interfaces
An interface is a blueprint of a class. It has constants variables and abstract methods only.
Features
1.All methods declared in an interface must be public.
2.All methods in the interface must be implemented within a class.
3.Classes may implement more than one interface.
4.Interfaces can be extended like classes using extends keyword.
5.The class implementing the interface must use the exact same method signature as are defined
in the interface.
6.Interface can’t create object.
<?php
interface A
{
function display();
}
class B implements A
{
public function display()
{
echo "derived class<br>";
}
}
$s1=new B();
$s1->display();
?>
Encapsulation
1. The ability to hide the details of implementation is known as encapsulation.
2. The Encapsulation both data & code are bind together & keep both safe from outside
method &misuse.
3. The data & method wrap up into a single unit called as class.
11 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
4. The encapsulation is used for protection of a class internal data from code outside that
class & hiding the details of implementation.
12 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
Web Techniques
Variables
PHP provide several predefined variables such variables called as superglobals.
They are predefined variable that are available in all scopes throughout a script.
Superglobals are defined as follows
• $GLOBALS — HTTP Global variable
• $_SERVER — Server and execution environment information
• $_GET — HTTP GET variables
• $_POST — HTTP POST variables
• $_FILES — HTTP File Upload variables
• $_REQUEST — HTTP Request variables
• $_SESSION — Session variables
• $_ENV — Environment variables
• $_COOKIE — HTTP Cookies
$_SERVER
$_SERVER is a PHP super global variable which holds information about headers, paths, and
script locations.
<?php
echo $_SERVER['SCRIPT_NAME'];
?>
<?php
foreach($_SERVER as $k=>$v)
{
echo $k. " ";
echo $v;
echo "<br>";
}
?>
13 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
The following table lists the most important elements that can go inside $_SERVER:
Element/Code Description
$_SERVER['PHP_SELF']
Returns the filename of the currently executing
script
$_SERVER['GATEWAY_INTERFACE']
Returns the version of the Common Gateway
Interface (CGI) the server is using
$_SERVER['SERVER_ADDR'] Returns the IP address of the host server
$_SERVER['SERVER_NAME']
Returns the name of the host server (such as
www.vision.com)
$_SERVER['SERVER_SOFTWARE']
Returns the server identification string (such as
Apache/2.2.24)
$_SERVER['SERVER_PROTOCOL']
Returns the name and revision of the information
protocol (such as HTTP/1.1)
$_SERVER['REQUEST_METHOD']
Returns the request method used to access the
page (such as POST)
$_SERVER['REQUEST_TIME']
Returns the timestamp of the start of the request
(such as 1377687496)
$_SERVER['QUERY_STRING']
Returns the query string if the page is accessed via
a query string
$_SERVER['HTTP_ACCEPT']
Returns the Accept header from the current
request
$_SERVER['HTTP_ACCEPT_CHARSET']
Returns the Accept_Charset header from the
current request (such as utf-8,ISO-8859-1)
$_SERVER['HTTP_HOST'] Returns the Host header from the current request
$_SERVER['HTTP_REFERER'] Returns the complete URL of the current page
$_SERVER['HTTPS']
Is the script queried through a secure HTTP
protocol
$_SERVER['REMOTE_ADDR']
Returns the IP address from where the user is
viewing the current page
$_SERVER['REMOTE_HOST']
Returns the Host name from where the user is
viewing the current page
14 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
$_SERVER['REMOTE_PORT']
Returns the port being used on the user's machine
to communicate with the web server
$_SERVER['SCRIPT_FILENAME']
Returns the absolute pathname of the currently
executing script
$_SERVER['SERVER_PORT']
Returns the port on the server machine being used
by the web server for communication (such as 80)
$_SERVER['SERVER_SIGNATURE']
Returns the server version and virtual host name
which are added to server-generated pages
$_SERVER['PATH_TRANSLATED']
Returns the file system based path to the current
script
$_SERVER['SCRIPT_NAME'] Returns the path of the current script
$_SERVER['SCRIPT_URI'] Returns the URI of the current page
GET POST
The GET method sends the encoded user
information appended to the page
request. The page and the encoded
information are separated by the ?
character.e.g
http://www.test.com/index.htm?nam
e1=value1&name2=value2
he POST method transfers information via HTTP
headers.e.g
http://www.test.com/index.htm
It is by default method It is not by default method
The GET method is restricted to send upto
1024 characters only.
The POST method does not have any restriction
on data size to be sent.
GET method is not used for password or
other sensitive information to be sent to the
server.
POST method is used for password or other
sensitive information to be sent to the server.
GET can't be used to send binary data to the
server.
POST can be used to send binary data to the
server.
Self Processing Form
To combine the HTML document containing the form and PHP script that processes it all
into one script
15 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
When user submits the form information by pressing the submit button, the action attribute of the
form reference the URL of the same page that displayed in the form
This can done by $_SERVER[‘PHP_SELF’] array.
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="fname">
<input type="submit">
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
// collect value of input field
}
?>
</form>
</body>
</html>
Sticky Forms
A sticky form is simply a standard HTML form that remembers how you filled it out. This is a
particularly nice feature for end users, especially if you are requiring them to resubmit a form.
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="fname" value="<?php if (isset($_POST['fname'])) echo
$_POST['fname'] ?>">
<input type="submit">
</form>
</body>
16 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
</html>
Headers function
HTTP response that server sends back to a client contains
• header that identify the type of content in the body of the response,
• The server that sent the response,
• How many bytes are in the body, when response was sent etc.
This information can be retrieved using header function
Syntax
header(string,replace,http_response_code)
Parameter Description
String Required. Specifies the header string to send
Replace
Optional. Indicates whether the header should replace previous or add a
second header. Default is TRUE (will replace). FALSE
http_response_code Optional. Forces the HTTP response code to the specified value
Possible Parameters of Header
1.Content Type:The content type header identifies the type of document
being returned. for e.g for HTML document, it is text/html for plain text
it is force the browser to treat the page is specified.
<?php
header('Content-Type: text/plain');
17 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
?>
2.Redirection:To sends browser to new URL by setting the location of header
<?php
header("location:http://www.google.com/");
?>
3.Expiration:Server can explicitly inform the browser the
specified date & time for document to expire.
<?php
// Date in the past
header("Expires: Mon, 26 Jul 2000 05:00:00 GMT");
?>
18 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
XML
What is XML?
• XML stands for Extensible Markup Language
• XML is a markup language much like HTML
• XML is text based markup language that enables to store data
in structure format by using meaningful tag.
• XML tags are not predefined. You must define your own tags
• XML is designed to be self-descriptive
• XML is a W3C(World Wide web Consortium) Recommendation
Difference Between HTML &XML
HTML XML
Markup language for displaying web pages in
a web browser. Designed to display data with
focus on how the data looks
Markup language defines a set of rules for
encoding documents that can be read by both
humans and machines. Designed with focus on
storing and transporting data
HTML tags are predefined XML tags are not predefined but Custom tags
can be created .
Display a web page Transport data between the application and the
database.
No strict rules. Browser will still generate data
to the best of its ability
Strict rules must be followed or processor will
terminate processing the file
Search data in HTML is difficult because of
predefined tag
Search data in XML is easy because of user defined
tag.
<html>
<body>
1
amol
</body>
<?xml version="1.0" encoding="ISO-8859-1"?>
<student >
<stud>
<rollno>1</rollno>
<name>amol</name>
</stud>
19 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
</html> </student>
Feature of XML
1.XML Separates Data from HTML
if you need to display dynamic data in your HTML document, it will take a lot of work to edit
the HTML each time the data changes.With XML, data can be stored in separate XML files.
This way you can concentrate on using HTML/CSS for display and layout, and be sure that
changes in the underlying data will not require any changes to the HTML.
With a few lines of JavaScript code, you can read an external XML file and update the data
content of your web page.
2 XML Simplifies Data Sharing
In the real world, computer systems and databases contain data in incompatible formats.
XML data is stored in plain text format. This provides a software- and hardware-independent
way of storing data.
This makes it much easier to create data that can be shared by different applications.
3.XML Simplifies Data Transport
One of the most time-consuming challenges for developers is to exchange data between
incompatible systems over the Internet.
Exchanging data as XML greatly reduces this complexity, since the data can be read by different
incompatible applications.
4. XML Simplifies Platform Changes
Upgrading to new systems (hardware or software platforms), is always time consuming. Large
amounts of data must be converted and incompatible data is often lost.
XML data is stored in text format. This makes it easier to expand or upgrade to new operating
systems, new applications, or new browsers, without losing data.
5.XML Makes Your Data More Available
20 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
Different applications can access your data, not only in HTML pages, but also from XML data
sources.
XML DOCUMENT STRUCTURE OR COMPONENENT OF XML
Document Prolog Section
Document Prolog comes at the top of the document, before the root element. This section
contains −
• XML declaration
• Document type declaration
XML declaration
XML declaration contains details that prepare an XML processor to parse the XML document.
It is optional, but when used, it must appear in the first line of the XML document.
<?xml version = "version_number" encoding = "encoding_declaration" ?>
It defines the XML version (1.0) and the encoding information such as ISO-8859-1,UTF-8,UTF-
16
e.g
<?xml version="1.0" encoding="ISO-8859-1"?>
Document Elements Section
Document Elements are the building blocks of XML. Elements can behave as containers to hold
text, elements, attributes etc.
<element-name attribute1 attribute2>
....content
</element-name>
21 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
• element-name is the name of the element. The name its case in the start and end tags
must match.
A markup construct that begins with < and ends with >. Tags come in three ways
• start-tags; for example: <section>
• end-tags; for example: </section>
• empty-element tags; for example: <section/>
• attribute1, attribute2 are attributes of the element separated by white spaces. An
attribute defines a property of the element. It associates a name with a value, which is a
string of characters. An attribute is written as name=”value”
e.g <stud course="bcs">
For e.g
1.a.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<student >
<stud>
<rollno>1</rollno>
<name>amol</name>
</stud>
</student>
2.b.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<student>
<stud course="bca">
<rollno >1</rollno>
<name>amol</name>
</stud>
<stud course="bcs">
<rollno>2</rollno>
<name>amit</name>
</stud>
</student>
22 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
Where
<student>=>It is root element
<stud>,<rollno>,<name>=>It is element.
course=bcs,course=bca=>Attribute & its value
XML Syntax Rules
1 All XML Elements Must Have a Closing Tag
In HTML, some elements do not have to have a closing tag:
<p>This is a paragraph.
<br>
In XML, it is illegal to omit the closing tag. All elements must have a closing tag:
<p>This is a paragraph.</p>
<br />
2. XML Tags are Case Sensitive
XML tags are case sensitive. The tag <Letter> is different from the tag <letter>.
Opening and closing tags must be written with the same case:
<Message>This is incorrect</message>
<message>This is correct</message>
3.XML Elements Must be Properly Nested
In HTML, you might see improperly nested elements:
<b><i>This text is bold and italic</b></i>
In XML, all elements must be properly nested within each other:
<b><i>This text is bold and italic</i></b>
4.XML Documents Must Have a Root Element
XML documents must contain one element that is the parent
of all other elements. This element is called the root element.
23 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
5.XMLAttribute Values Must be Quoted
XML elements can have attributes in name/value pairs just like in HTML.
• XML, the attribute values must always be quoted.
<student rollno=”1”>
<name>amol</name>
<address>pune</address>
</student>
• It doesn’t provide two values for same attribute in the same start tag
• Attribute name in XML are case sensitive
6.Comments in XML
The syntax for writing comments in XML is similar to that of HTML.
<!-- This is a comment -->
7.References:
A references allows us to include additional text or markup in an XML document .Reference
always begin with the character “&”(Which is specially reserved). And end with the character
“;”
XML 2 type of reference
1.Entity References:
Some characters have a special meaning in XML.
If you place a character like "<" inside an XML element, it will generate an error because the
parser interprets it as the start of a new element.
24 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
There are 5 predefined entity references in XML:
&lt; < less than
&gt; > greater than
&amp; & ampersand
&apos; ' Apostrophe
&quot; " quotation mark
Eg
<message>salary < 1000</message>
converted into entity refereance <message>salary &lt; 1000</message>
2.Character References: A character reference gives the number of the particular Unicode
character it stands for, in either decimal or hexadecimal.
Decimal character references look like &#1114; hexadecimal character references
have an extra x after the &#;, that is, they look like &#x45A;
e.g
<data>
&#x3C3;&#x3BF;&#x3C6;&#x3CC;&#x3C2;
&#x3AD;&#x3B1;&#x3C5;&#x3C4;&#x3CC;&#x3BD;
&#x3B3;&#x3B9;&#x3B3;&#x3BD;&#x3CE;&#x3C3;&#x3BA;&#x3B5;&#x3B9;
</data>
Application of XML
1.Web publishing
XML allows the developers to save the data into XML files & use XSLT transformation
API’S to generate content in required format such as HTML,XHTML
2.Web Searching
It can use XML data & then search the data from the XML file & display to the user
3.Data Transfer
It can use XML to save configuration or business data for our application
4.Created Other language
Many language are created using XML such as WML
25 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
XML PARASER
XML parser to create, read and manipulate an XML document.
XML data binding
It refers to a means of representing information in an XML document as a business object in
computer memory. This allows applications to access the data in the XML from the object rather
than using the DOM or SAX to retrieve the data from a direct representation of the XML itself.
Or
XML data binding is the process of representing information in an XML document as an object in
computer memory (deserialization). With XML data binding, applications access XML data direct
from the object instead of using the Document Object Model (DOM) to retrieve it from the XML file.
Using XML binding, you can integrate XML data into a business rule application.
XML PARSER
An XML Parser is a parser that is designed to read XMLand create a way for programs to
use XML
The XML parser defines the properties and methods for accessing and editing XML.
All major browsers have a built-in XML parser to access and manipulate XML.
1.xml_parser_create()
The xml_parser_create() function creates an XML parser.This function returns a resource handle
to be used by other XML functions on success, or FALSE on failure.
Syntax
xml_parser_create(encoding)
2. xml_parse_into_struct()
The xml_parse_into_struct() function parses XML data into an array.
This function parses the XML data into 2 arrays:
• Value array - containing the data from the parsed XML
• Index array - containing pointers to the location of the values in the Value array
This function returns 1 on success, or 0 on failure.
Syntax
xml_parse_into_struct(parser,xml,value_arr,index_arr)
26 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
Parameter Description
Parser Required. Specifies XML parser to use
Xml Required. Specifies XML data to parse
value_arr Required. Specifies the target array for the XML data
index_arr Optional. Specifies the target array for index data
<?php
$xmlfile = 'test.xml';
$xmlparser = xml_parser_create();
fp = fopen($xmlfile, 'r');
$xmldata = fread($fp, 4096);
xml_parse_into_struct($xmlparser,$xmldata,$values);
xml_parser_free($xmlparser);
print_r($values);
?>
In PHP there are two major types of XML parsers:
1. SimpleXML
SimpleXML is a tree-based parser.
SimpleXML is an extension that allows us to easily manipulate and get XML data.
SimpleXML provides an easy way of getting an element's name, attributes and textual content if
you know the XML document's structure or layout.
SimpleXML turns an XML document into a data structure you can iterate through like a
collection of arrays and objects.
27 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
SimpleXML function
1.simplexml_load_file() 2.simplexml_load_string()
The simplexml_load_file() function
loads an XML document into an
object.
This function returns FALSE on
failure.
<?php
$xml = simplexml_load_file('a.xml');
var_dump($xml);
?>
The simplexml_load_string() function loads an XML string
into an object.
This function returns FALSE on failure.
<?php
$xmlstring = <<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<student>
<stud>
<rollno>1</rollno>
<name>amol</name>
</stud>
</student>
XML;
$xml = simplexml_load_string($xmlstring);
var_dump($xml);
?>
*4.children() *5. Retrive attribute all nodes
The children() function gets the child
nodes of the specified XML node.
<?php
$xml = simplexml_load_file("a.xml");
foreach ($xml->children() as $b)
{
echo "rollno”.$b->rollno;
echo "name”.$b->name;
<?php
$xml=simplexml_load_file("b.xml");
foreach($xml->children() as $b)
{
echo $b[0]['course'];
echo "<br>";
}
?>
28 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
}
?>
6.simplexml_import_dom() 7. asXML()
The simplexml_import_dom()
converts a DOM node to a
SimpleXMLElement object.
This function returns FALSE on
failure.
<?php
$dom = new domDocument;
$dom-
>loadXML("<stud><name>amol</na
me></stud>");
$xml =
simplexml_import_dom($dom);
echo $xml->name;
?>
asXML()
It return a well-formed XML string
syntax
asXML(filename);
<?php
$xml = simplexml_load_file('a.xml');
header('Content-Type: text/xml');
echo $xml->asXML();
?>
addChild()
The addChild() function adds a child element to the SimpleXML
element.
syntax
addChild(name,value);
<?php
$xml = new SimpleXMLElement('<?xml version="1.0"
encoding="UTF-8"?><CricketTeam/>');
$s=$xml->addChild('team');
$s->addchild('player','aa');
29 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
header('Content-Type: text/xml');
echo $xml->asXML();
?>
addAttribute()
The addAttribute() function adds an
attribute to the SimpleXML element.
syntax
addAttribute(name,value)
<?php
$xml = new
SimpleXMLElement('<?xml
version="1.0" encoding="UTF-
8"?><CricketTeam/>');
$s=$xml->addChild('team');
$s->AddAttribute('country','india');
$s->addchild('player','aa');
header('Content-Type: text/xml');
echo $xml->asXML();
?>
2.XML DOM
• It Is tree based parser
30 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
• DOM is stands for Document Object Model.
• It defines a standard way to access and manipulate documents. The Document Object
Model (DOM) is a programming API for HTML and XML documents. It defines the
logical structure of documents and the way a document is accessed and manipulated.
• DOM defines a standard way to access and manipulate XML documents.
Dom Function
1. load
Loads an XML document from a file.
2.DOMDocument
Creates a new DOMDocument object.
3.saveXML
Dumps the internal XML tree back into a string
4.loadXML
Loads an XML document from a string.7.
5. save
It load XML tree into a specified file
6. appendChild()
It adds a new child node to the end of the list of children of the node
7. getAttribute()
Returns the value of an attribute
8.removeChild()
Removes a child node
9.replaceChild()
Replace a child node
10. removeAttribute
Remove a specified attribute
11. getElementsByTagName
Return array with nodes with given tagname in the documenet or empty array if not found
31 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
eg
<?php
$xd = new DOMDocument();
$xd->load("a.xml");
echo $xd->saveXML();
echo $xd->save(“a.doc”)
?>
Display values from xml file
<?php
$doc=new DOMDocument();
$doc->load("stud.xml");
$bk=$doc->getElementsByTagName("stud");
foreach($bk as $s)
{
echo "<br>course is".$s->getAttribute("course");
$rn=$s->getElementsByTagName("rollno");
$v1=$rn->item(0)->nodeValue;
echo "<br>Rollno is $v1";
$nm=$s->getElementsByTagName("name");
$v2=$nm->item(0)->nodeValue;
echo "<br>Name is $v2";
}
?>
32 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
AJAX
What is AJAX ?
• AJAX stands for Asynchronous JavaScript and XML.
• AJAX is about updating parts of a web page, without reloading the whole page.
• AJAX is a technique for creating fast and dynamic web pages.
• AJAX allows web pages to be updated asynchronously by exchanging small
amounts of data with the server behind the scenes. This means that it is possible to
update parts of a web page, without reloading the whole page.
Asynchronous :The script will send a request to the server, and continue it's execution
without waiting for the reply. As soon as reply is received a browser event is fired, which
in turn allows the script to execute associated actions
A synchronous request blocks the client until operation completes
An asynchronous request doesn’t block the client
Applications using AJAX
Google Maps, Gmail, Youtube, twitter, Facebook
33 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
How AJAX Works
34 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
1. User sends a request from the UI and a javascript call goes to XMLHttpRequest object.
2. HTTP Request is sent to the server by XMLHttpRequest object.
3. Server interacts with the database using JSP, PHP, Servlet, ASP.net etc.
4. Data is retrieved.
5. Server sends XML data to the XMLHttpRequest callback function.
6. HTML and CSS data is displayed on the browser.
1. The XMLHttpRequest Object
The keystone of AJAX is the XMLHttpRequest object.
2. XMLHttpRequest is used for asynchronous communication between client and server
It performs following operations:
1. Sends data from the client in the background
2. Receives the data from the server
35 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
3. Updates the webpage without reloading it.
3. All modern browsers (IE7+, Firefox, Chrome, Safari, and Opera) have a built-in
XMLHttpRequest object.
4. Syntax for creating an XMLHttpRequest object:
variable=new XMLHttpRequest();
• Old versions of Internet Explorer (IE5 and IE6) uses an ActiveX Object:
variable=new ActiveXObject("Microsoft.XMLHTTP");
e.g
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
Methods of XMLHttpRequest object
To send a request to a server, we use the open() and send() methods of the XMLHttpRequest
object:
Syntax
open(method,url,async)
xmlhttp.send();
Where
method: the type of request: GET or POST
url: the location of the file on the server
36 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
async: true (asynchronous) or false (synchronous)
send() Sends the request to the server (used for GET)
send(string) Sends the request to the server (used for POST)
eg
xmlhttp.open("GET","ajax_info.php",true);
Properties of XMLHttpRequest object
1 onreadystatechange
It is called whenever readystate attribute changes.
2. readyState
It represents the state of the request. It ranges from 0 to 4.
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready
status
200: "OK
404: Page not found
3.Server Response
responseText get the response data as a string
responseXML get the response data as XML data
To get the response from a server, use the responseText or responseXML property of the
XMLHttpRequest object.
37 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
e.g
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("t").innerHTML=xmlhttp.responseText;
}
}
Example
1.To display length of string using AJAX
<html>
<head>
<script>
function show(str)
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
38 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("t").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://localhost/d.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form method="get">
Enter string:
<input type="text" onkeyup="show(this.value)">
<br>
</form>
length is:
<span id="t">
</span>
</body>
</html>
d.php
<?php
$q=$_GET["q"];
$len=strlen($q);
echo "length is ".$len;
?>
39 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
2. To display student details using selected sno
Stud(sno,sname,per)
<html>
<head>
<script>
function show(str)
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("t").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://localhost/d.php?q="+str,true);
xmlhttp.send();
}
</script>
40 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
</head>
<body>
<form method="get">
Enter sno:
<input type="text" onkeyup="show(this.value)">
<br>
</form>
student details is:
<span id="t">
</span>
</body>
</html>
d.php
<?php
$q=$_GET["q"];
$con = mysql_connect("localhost", "root", "");
$db= mysql_select_db("bca",$con);
$i=0;
$sql = "SELECT * from stud where sno=$q";
$res = mysql_query($sql,$con);
$cnt = mysql_numrows($res);
While($i< $cnt)
{
echo "<br>sno is ".mysql_result($res,$i,0);
echo "<br>name is ".mysql_result($res,$i,1);
echo "<br>per is ".mysql_result($res,$i,2);
$i++;
}
mysql_close($con);
?>
41 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
3 To display book details from XML file
b.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title>comp</title>
<author>mm</author>
<year>2005</year>
<price>30.00</price>
</book>
<book>
<title>math</title>
<author>nn</author>
<year>2005</year>
<price>30.00</price>
</book>
</bookstore>
HTML file
<html>
<head>
<script>
function show(str)
{
42 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("t").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://localhost/d.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form method="get">
Enter title:
<input type="text" onkeyup="show(this.value)">
<br>
</form>
43 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
book details is:
<span id="t">
</span>
</body>
</html>
d.php
<?php
$q=$_GET["q"];
$xml=simplexml_load_file("b.xml");
foreach($xml->children() as $b)
{
if( $b->title==$q)
{
echo "title ".$b->title;
echo "author ". $b->author;
echo "year ".$b->year;
echo "price".$b->price;
}
}
?>
4 To display addition
Html file
<html>
<head>
<script>
function show()
{
44 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
var t1 = document.getElementById('t1').value;
var t2= document.getElementById('t2').value;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("t").innerHTML=xmlhttp.responseText;
}
}
var q1= "t1="+t1;
var q2="&t2="+t2;
xmlhttp.open(“GET”, “http://localhost/d.php?”q1+q2, true);
45 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
xmlhttp.send();
}
</script>
</head>
<body>
<form method="get">
Enter no1:
<input type="text" id="t1">
<br>
Enter no2:
<input type="text" id="t2">
<br>
<input type="button" value="add" onclick="show()">
</form>
addtion is:
<span id="t">
</span>
</body>
</html>
d.php
<?php
46 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
$a=$_GET['t1'];
$b=$_GET['t2'];
$c=$a+$b;
echo $c;
?>
AJAX Advantages
AJAX Concept
AJAX is not a difficult, you can easy implement AJAX in a meaningful manner. Some IDE are
help us to implement AJAX.
Speed
Reduce the server traffic in both side request. Also reducing the time consuming on both side
response.
Interaction
AJAX is much responsive, whole page(small amount of) data transfer at a time.
XMLHttpRequest
XMLHttpRequest has an important role in the Ajax web development technique.
XMLHttpRequest is special JavaScript object that was designed by Microsoft. XMLHttpRequest
object call as a asynchronous HTTP request to the Server for transferring data both side.
Asynchronous calls
AJAX make asynchronous calls to a web server. This means client browsers are avoid waiting
for all data arrive before start the displaying.
Form Validation
Form are common element in web page. Validation should be instant and properly by using
AJAX concept
Bandwidth Usage
No require to completely reload page again. AJAX is improve the speed and performance.
47 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
AJAX Disadvantages
1 View source is allowed and anyone can view the code source written for AJAX.
2 It can increase design and development time
3 JavaScript disabled browsers cannot use the application.
4 Security is less in AJAX application as all files are downloaded at client side.
48 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
WEB SERVICES
What is Web Service?
A Web Service is can be defined by following ways:
• is a client server application or application component for communication.
• method of communication between two devices over network.
• is a software system for interoperable machine to machine communication.
• is a collection of standards or protocols for exchanging information between two devices
or application.
Let's understand it by the figure given below:
OR
A web service is a collection of open protocols and standards used for exchanging data between
applications or systems. Software applications written in various programming languages and
running on various platforms can use web services to exchange data over computer networks.
This interoperability (e.g., between Java and Python, or Windows and Linux applications) is due
to the use of open standards.
Web Services –Characteristics
• XML-based
By using XML as the data representation layer for all web services protocols and
technologies that are created.
49 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
• Loosely coupled
A consumer of a web service is not tied to that web service directly the web service
interface can change over time without compromising the client's ability to interact
with the service. A tightly coupled system implies that the client and server logic are
closely tied to one another, implying that if one interface changes, the other must also
be updated. Adopting a loosely coupled architecture tends to make software systems
more manageable and allows simpler integration between different systems.
• Ability to be Synchronous or Asynchronous
Synchronicity refers to the binding of the client to the execution of the service. In
synchronous invocations, the client blocks and waits for the service to complete its
operation before continuing. Asynchronous operations allow a client to invoke a service
and then execute other functions.
• Supports Remote Procedure Calls(RPCs)
Web services allow clients to invoke procedures, functions, and methods on remote
objects using an XML-based protocol.
• Supports Document Exchange
One of the key advantages of XML is its generic way of representing not only data, but
also complex documents. These documents can be as simple as representing a current
address, or they can be as complex as representing an entire book or Request for
Quotation (RFQ). Web services support the transparent exchange of documents to
facilitate business integration.
• Platform-independence
It is platform independence
• Language-independence
It is language independence
Web Services - Architecture
There are two ways to view the web service architecture:
50 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
• The first is to examine the individual roles of each web service actor.
• The second is to examine the emerging web service protocol stack.
Web Service Roles
There are three major roles within the web service architecture:
Service Provider
This is the provider of the web service. The service provider implements the service and makes it
available on the Internet.
Service Requestor
This is any consumer of the web service. The requestor utilizes an existing web service by
opening a network connection and sending an XML request.
Service Registry
This is a logically centralized directory of services. The registry provides a central place where
developers can publish new services or find existing ones. It therefore serves as a centralized
clearing house for companies and their services.
Web Service Protocol Stack
51 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
A second option for viewing the web service architecture is to examine the emerging web service
protocol stack. The stack is still evolving, but currently has four main layers.
Service Transport
This layer is responsible for transporting messages between applications. Currently, this layer
includes Hyper Text Transport Protocol (HTTP), Simple Mail Transfer Protocol (SMTP), File
Transfer Protocol (FTP), and newer protocols such as Blocks Extensible Exchange Protocol
(BEEP).
XML Messaging
This layer is responsible for encoding messages in a common XML format so that messages can
be understood at either end. Currently, this layer includes XML-RPC and SOAP.
Service Description
This layer is responsible for describing the public interface to a specific web service. Currently,
service description is handled via the Web Service Description Language (WSDL).
Service Discovery
This layer is responsible for centralizing services into a common registry and providing easy
publish/find functionality. Currently, service discovery is handled via Universal Description,
Discovery, and Integration (UDDI).
As web services evolve, additional layers may be added and additional technologies may be
added to each layer.
Web Service Components
52 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
There are three major web service components.
1. SOAP
2. WSDL
3. UDDI
1 WSDL
• WSDL stands for Web Services Description Language.
• WSDL was developed jointly by Microsoft and IBM.
• WSDL is used to describe web services
• WSDL is written in XML
• WSDL definition describes how to access a web service and what operations it will
perform.
• Web services and describes how service providers and requesters communicate with one
another.
WSDL Documents
An WSDL document describes a web service. It specifies the location of the service, and the
methods of the service, using these major elements:
Element Description
<types> Defines the (XML Schema) data types used by the web service
<message> Defines the data elements for each operation
<portType>
Describes the operations that can be performed and the messages
involved.
Type Definition
One-way
The operation can receive a message but will
not return a response
Request-response
The operation can receive a request and will
return a response
Solicit-response
The operation can send a request and will wait
for a response
Notification The operation can send a message but will not
53 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
wait for a response
<binding> Defines the protocol and data format for each port type
The main structure of a WSDL document looks like this:
<definitions>
<types>
data type definitions........
</types>
<message>
definition of the data being communicated....
</message>
<portType>
set of operations......
</portType>
<binding>
protocol and data format specification....
</binding>
</definitions>
e.g
<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
54 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
<output message="getTermResponse"/>
</operation>
</portType>
<binding type="glossaryTerms" name="b1">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation>
<soap:operation soapAction="http://example.com/getTerm"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>
Where
<portType> element defines "glossaryTerms" as the name of a port, and "getTerm" as the name
of an operation.
The "getTerm" operation has an input message called "getTermRequest" &output message
called "getTermResponse".
The <message> elements define the parts of each message and the associated data types
The binding element has two attributes - name and type.
The name attribute (you can use any name you want) defines the name of the binding, and the
type attribute points to the port for the binding, in this case the "glossaryTerms" port.
The soap:binding element has two attributes - style and transport.
The style attribute can be "rpc" or "document". In this case we use document. The transport
attribute defines the SOAP protocol to use. In this case we use HTTP.
The operation element defines each operation that the portType exposes.
For each operation the corresponding SOAP action has to be defined. You must also specify how
the input and output are encoded. In this case we use "literal".
2 SOAP
55 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
SOAP is an XML-based protocol for exchanging information between computers.
• SOAP is a communication protocol.
• SOAP is for communication between applications.
• SOAP is a format for sending messages.
• SOAP is designed to communicate via Internet.
• SOAP is platform independent.
• SOAP is language independent.
• SOAP is simple and extensible.
• SOAP allows you to get around firewalls.
• SOAP will be developed as a W3C standard.
A SOAP message is an ordinary XML document containing the following elements:
An Envelope element that identifies the XML document as a SOAP message
A Header element that contains header information
A Body element that contains call and response information
A Fault element containing errors and status information
<?xml version="1.0"?>
<soap: Envelope xmlns: soap="http://www.w3.org/2001/12/soap-envelope"soap:
encodingStyle="http://www.w3.org/2001/12/soapencoding">
<soap:Header>
...
----------
</soap:Header>
<soap:Body>
...<soap:Fault>
...
</soap:Fault>
</soap:Body>
</soap:Envelope>
56 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
3.UDDI
• UDDI stands for Universal Description, Discovery, and Integration.
• UDDI is an XML-based standard for describing, publishing, and finding web services.
• UDDI, defines the standard interfaces and mechanisms for registries intended for
publishing and storing descriptions of network services in terms of XML messages.
• Web services model, UDDI provides the registry for Web services to function as the
service providers to populate the registry with service descriptions and service types and
the service requestors to query the registry to find and locate the services. It enables Web
applications to interact with a UDDI-based registry using SOAP messages. T
• A UDDI registry can be in two modes public mode and private mode
• A public UDDI registry is available for everyone to publish/query the business and
service information on the Internet.
• A private UDDI registry is operated by a single organization or a group of
collaborating organizations to share the information that would be available only to the
participating bodies.
• Businesses can use a UDDI registry at three levels:-
57 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
1.White Pages
White pages give information about the business supplying the service. This includes the
name of the business and a description of the business - potentially in multiple languages.
Using this information, it is possible to find a service.
2.Yellow pages
Businesses that intend to classify their information based on categorizations (also
known as classification schemes or taxonomies) make use of the UDDI registry as yellow
pages..
3.Green Pages
Green pages are used to describe how to access a Web Service, with information on the
service bindings. Some of the information is related to the Web Service - such as the
address of the service and the parameters, and references to specifications of interfaces.
XML-RPC(Remote Procedure Call)
• This is the simplest XML-based protocol for exchanging information between computers.
• RPC stands for Remote Procedure Call. As its name indicates, it is a mechanism to call a
procedure or a function available on a remote computer
• XML-RPC is a simple protocol that uses XML messages to perform RPCs.
• Requests are encoded in XML and sent via HTTP POST.
• XML responses are embedded in the body of the HTTP response.
• XML-RPC is platform-independent.
• XML-RPC allows diverse applications to communicate.
• XML-RPC's most obvious field of application is connecting different kinds of
environments, allowing Java to talk with Perl, Python, ASP, and so on.
• XML-RPC permits programs to make function or procedure calls across a network.
• XML-RPC uses the HTTP protocol to pass information from a client computer to a
server computer.
• XML-RPC uses a small XML vocabulary to describe the nature of requests and
responses.
• XML-RPC client specifies a procedure name and parameters in the XML request, and
the server returns either a fault or a response in the XML response.
• XML-RPC parameters are a simple list of types and content - structs and arrays are the
most complex types available.
58 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
• XML-RPC has no notion of objects and no mechanism for including information that
uses other XML vocabulary.
• XML-RPC consists of three relatively small parts:
• XML-RPC data model : A set of types for use in passing parameters, return
values, and faults (error messages).
• XML-RPC request structures : An HTTP POST request containing method and
parameter information.
• XML-RPC response structures : An HTTP response that contains return values
or fault information.
59 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
PHP FRAMEWORK
What is PHP Framwork?
A framework, or software framework, is a platform for developing software
applications. It provides a foundation on which software developers can build programs
for a specific platform. A framework may also include code libraries, a compiler,
and other programs used in the software development process.
List of Framework
• Joomla
• Drupal
• Word press
• CakePHP. ...
• Zend Framework. ...
• Symfony
• Seagull
• Yii.
Advantages PHP Frameworks
1.Speed up custom web application development
Nowadays, PHP programmers have to write web applications based on complex business
requirements. Likewise, they have to explore ways to make the web application deliver richer user
experience. The tools, features, and code snippets provided by PHP frameworks help developers
to accelerate custom web application development.
2. Simplify web application maintenance
Unlike other programming languages, PHP does not emphasize on code readability and
maintainability. The PHP frameworks simplify web application development and maintenance by
supporting model-view-controller (MVC) architecture. The developers can take advantage of
MVC architecture to divide a web application into models, views and controllers. They can use a
60 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
MVC framework for PHP to keep the application’s user interface and business logic layers
separated.
3. No need to write additional code
PHP, unlike other programming languages, does not allow programmers to express concepts
without writing longer lines of code. Hence, the PHP programmers have to write lengthy and
complex code while adding features or functionality to a website. The PHP frameworks reduce
coding time significantly by providing code generation feature. The code generation features
provided by certain PHP frameworks enable programmers to keep the source code of web
application clean and maintainable.
4. Work with databases more efficiently
Most PHP frameworks allow programmers to work with a number of widely used relational
databases.
5. Automate common web development tasks
While building a web application, developers have to perform a number of tasks in addition to
writing code. Some of these common web development tasks require programmers to invest
additional time and effort. The functions and tools provided by PHP frameworks help developers
to automate common web development tasks like caching, session management, authentication,
and URL mapping.
6.Protect websites from targeted security attacks
The built-in security features and mechanisms provided by PHP framework make it easier for
developers to protect the website from existing and emerging security threats
7.Perform unit testing efficiently
PHP frameworks support PHPUnit natively, and enable programmers to perform unit testing
smoothly
8.No need to increase web development cost
61 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
The developers also have option to choose from several open source web frameworks for PHP.
They can even available the features and tools provided by these open source PHP frameworks
speed up custom web application development without increasing project overheads.
Joomla Framework
1. Joomla is an open source Content Management System (CMS), which is used to build
websites and online applications.
2. The Content Management System (CMS) is a software which keeps track of the entire
data (such as text, photos, music, documents, etc.) which will be available on your
website. It helps in editing, publishing and modifying the content of the website.
3. It is free and extendable which is separated into front-end and back-end templates
(administrator).
4. Joomla is uses PHP &MySQL (used for storing the data).
5. 4. It support MVC architecture
Drupal Framework
1. Drupal is an open source Content Management System (CMS).It offeres flexibility in
design through simplicity.
2. Drupal uses LAMP server
L:Linux (Operating system)
62 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
A:Appache(Web Server)
M:MySQL(Data Storage)
P:PHP(Programming Lang)
4. It support MVC architecture
3.The architecture of Drupal contains the following layers
• Users
• Administrator
• Drupal
• PHP
• Web Server
• Database
63 Vision Academy
(9822506209/9823037693)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET )
Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT)
PHP
Application
• Government Application
• Small Business web portal
• Online System for reservation, media related web site etc
Contact:
Vision Academy Since 2005
Prof. Sachin Sir(MCS,SET)
9822506209/9823037693
www.visionacademe.com
Branch1:Nr Sm Joshi College,Abv Laxmi zerox,Ajikayatara Build,Malwadi Rd,Hadapsar
Branch2:Nr AM College,Aditya Gold Society,Nr Allahabad Bank ,Mahadevnager

More Related Content

Similar to PHP OOP Introduction

Framework prototype
Framework prototypeFramework prototype
Framework prototypeDevMix
 
Framework prototype
Framework prototypeFramework prototype
Framework prototypeDevMix
 
Framework prototype
Framework prototypeFramework prototype
Framework prototypeDevMix
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Alena Holligan
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingShivam Singhal
 
Inheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxInheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxnaeemcse
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3Toni Kolev
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Alena Holligan
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHPMichael Peacock
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppthenokmetaferia1
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Alena Holligan
 
Lecture 17 - PHP-Object-Orientation.pptx
Lecture 17 - PHP-Object-Orientation.pptxLecture 17 - PHP-Object-Orientation.pptx
Lecture 17 - PHP-Object-Orientation.pptxDavidLazar17
 
Demystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPDemystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPAlena Holligan
 
Lecture 6 inheritance
Lecture   6 inheritanceLecture   6 inheritance
Lecture 6 inheritancemanish kumar
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in phpCPD INDIA
 
PHP OOP Lecture - 04.pptx
PHP OOP Lecture - 04.pptxPHP OOP Lecture - 04.pptx
PHP OOP Lecture - 04.pptxAtikur Rahman
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5Sayed Ahmed
 

Similar to PHP OOP Introduction (20)

Framework prototype
Framework prototypeFramework prototype
Framework prototype
 
Framework prototype
Framework prototypeFramework prototype
Framework prototype
 
Framework prototype
Framework prototypeFramework prototype
Framework prototype
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Inheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxInheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptx
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHP
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016
 
Lecture 17 - PHP-Object-Orientation.pptx
Lecture 17 - PHP-Object-Orientation.pptxLecture 17 - PHP-Object-Orientation.pptx
Lecture 17 - PHP-Object-Orientation.pptx
 
Demystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPDemystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHP
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
 
Lecture 6 inheritance
Lecture   6 inheritanceLecture   6 inheritance
Lecture 6 inheritance
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
PHP OOP Lecture - 04.pptx
PHP OOP Lecture - 04.pptxPHP OOP Lecture - 04.pptx
PHP OOP Lecture - 04.pptx
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5
 

Recently uploaded

Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 

Recently uploaded (20)

Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 

PHP OOP Introduction

  • 1. 1 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP Introduction to Object Oriented Programming in PHP Class 1.It is blueprint of the object 2.The class contains the methods &properties Object It is instance of class <?php class phpClass { var $var1; var $var2 = "constant string"; function myfunc ($arg1, $arg2) { } …… …… } ?> <?php class student { var $rollno; var $name; function accept() { $this-> rollno=1; $this->name="amol"; } function display() {
  • 2. 2 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP echo "Rollno ".$this->rollno; echo "Name ".$this->name; } } $s1=new student; $s1->accept(); $s1->display(); ?> Note: • Variable declarations start with the special form var, which is followed by a conventional $ variable name. • -> is used to access properties & method of class. Use of this keyword: The $this is a keyword which represents the current object or current instance of class. $this is a special self-referencing variable that is used to access properties and methods from within the class. Constructor Constructor Functions are special type of functions which are called automatically whenever an object is created. PHP provides a special function called __construct() to define a constructor. Syntax function __connstruct(arglist) { }
  • 3. 3 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP Destructor Destructor function is called when an object is destroyed It can define a destructor function using function __destruct() Syntax function __destruct() { } <?php class student { var $rollno; var $name; function __construct($a,$b) { $this-> rollno=$a; $this->name=$b; } function display() { echo "Rollno ".$this->rollno; echo "Name ".$this->name; } function __destruct() { echo "destory"; } }
  • 4. 4 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP $s1=new student(1,"amol"); $s1->display(); ?> Visibility Public member:It can access a public method or property from inside or outside the class. Private member: It can access a private method or property only inside the class. Protected member: It can access a protected method or property available to class itself and to classes that inherited from it. Introspection Introspection is the ability of a program to examine an object's characteristics, such as its name, parent class (if any), properties, and methods Examine Classes Syntax Description class_exists(classname) This function returns true if classname is a defined otherwise false get_declared_classes() This function returns array of defined class get_class_methods(classname) This function return array of class method name get_class_vars(classname) This function return an array of default properties of the class get_parent_class(classname) It return name of parent class <?php class student { var $rollno; var $name;
  • 5. 5 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP function display() { echo "Rollno ".$this->rollno; echo "Name ".$this->name; } } $m=new student(); $a=class_exists('student'); echo "$a"; $b=get_declared_classes(); print_r($b); $c=get_class_vars('student'); print_r ($c); $d=get_class_methods('student'); print_r($d); echo is_object($m); echo get_class($m); print_r(get_object_vars($m)); ?> Examine Methods Syntax Description is_object(object) It return true if passed parameter is an object get_class(object) It return name of the class of an object get_object_vars(object) Gets the properties of the given object Inheritance PHP support inheritance concept.In a inheritance, the new class can inherit the properties and methods from old class.The old class is called base class or super class & new class is called derived class. The “extends” keyword is used for the inheritance. <?php class student { var $name; } class result extends student
  • 6. 6 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP { var $grade; function accept() { $this->name="amol"; $this-> grade="A"; } function display() { echo "Rollno ".$this->name; echo "Grade ".$this->grade; } } $s1=new result; $s1->accept(); $s1->display(); ?> Serialization Serailizing object means converting into byte representation that can be stored into a file. It can done using two function 1 serialize():It return a string containing a byte stream representation of any value that can be stored in PHP. String serialize(mixed $val) 2 unserialize():To turn back the serialized string into php variables. Mixed unserialize(String $val) <?php class student { var $rollno; var $name;
  • 7. 7 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP function accept() { $this-> rollno=1; $this->name="amol"; } function display() { echo "Rollno ".$this->rollno; echo "Name ".$this->name; } } $s1=new student; $s1->accept(); $ob=serialize($s1); $fp=fopen("c:a1.txt","w"); fwrite($fp,$ob); fclose($fp); $rob=unserialize($ob); $rob->display(); ?> __sleep and __wakeup function This function are used to notify objects that are being serialized or unsterilized serialize() checks if your class has a function with the magic name __sleep. If so, that function is being run prior to any serialization. It can clean up the object and is supposed to return an array with the names of all variables of that object that should be serialized. If the method doesn't return anything then NULL is serialized and E_NOTICE is issued. unserialize() checks for the presence of a function with the magic name __wakeup. If present, this function can reconstruct any resources that object may have. <?php class student { var $rollno;
  • 8. 8 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP var $name; function accept() { $this-> rollno=1; $this->name="amol"; } public function __sleep() { echo "sleep calling<br>"; return array('rollno','name'); } function __wakeup() { echo "Waking up..."; } } $s1=new student; $s1->accept(); $ob=serialize($s1); echo "$ob"; $rob=unserialize($ob); print_r($rob); ?> Method overriding The same method (same prototype) of base class overrides in their derived class known as method overriding <?php class base { function display() { echo "base class<br>";
  • 9. 9 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP } } class derived extends base { function display() { parent::display(); echo "derived class<br>"; } } $s1=new derived; $s1->display(); ?> Abstract Class An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. abstract method:A method that is declared as abstract and does not have implementation (no body)is known as abstract method <?php abstract class A { abstract function display(); } class B extends A { function display() { echo "derived class<br>"; } } $s1=new B(); $s1->display();
  • 10. 10 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP ?> Interfaces An interface is a blueprint of a class. It has constants variables and abstract methods only. Features 1.All methods declared in an interface must be public. 2.All methods in the interface must be implemented within a class. 3.Classes may implement more than one interface. 4.Interfaces can be extended like classes using extends keyword. 5.The class implementing the interface must use the exact same method signature as are defined in the interface. 6.Interface can’t create object. <?php interface A { function display(); } class B implements A { public function display() { echo "derived class<br>"; } } $s1=new B(); $s1->display(); ?> Encapsulation 1. The ability to hide the details of implementation is known as encapsulation. 2. The Encapsulation both data & code are bind together & keep both safe from outside method &misuse. 3. The data & method wrap up into a single unit called as class.
  • 11. 11 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP 4. The encapsulation is used for protection of a class internal data from code outside that class & hiding the details of implementation.
  • 12. 12 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP Web Techniques Variables PHP provide several predefined variables such variables called as superglobals. They are predefined variable that are available in all scopes throughout a script. Superglobals are defined as follows • $GLOBALS — HTTP Global variable • $_SERVER — Server and execution environment information • $_GET — HTTP GET variables • $_POST — HTTP POST variables • $_FILES — HTTP File Upload variables • $_REQUEST — HTTP Request variables • $_SESSION — Session variables • $_ENV — Environment variables • $_COOKIE — HTTP Cookies $_SERVER $_SERVER is a PHP super global variable which holds information about headers, paths, and script locations. <?php echo $_SERVER['SCRIPT_NAME']; ?> <?php foreach($_SERVER as $k=>$v) { echo $k. " "; echo $v; echo "<br>"; } ?>
  • 13. 13 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP The following table lists the most important elements that can go inside $_SERVER: Element/Code Description $_SERVER['PHP_SELF'] Returns the filename of the currently executing script $_SERVER['GATEWAY_INTERFACE'] Returns the version of the Common Gateway Interface (CGI) the server is using $_SERVER['SERVER_ADDR'] Returns the IP address of the host server $_SERVER['SERVER_NAME'] Returns the name of the host server (such as www.vision.com) $_SERVER['SERVER_SOFTWARE'] Returns the server identification string (such as Apache/2.2.24) $_SERVER['SERVER_PROTOCOL'] Returns the name and revision of the information protocol (such as HTTP/1.1) $_SERVER['REQUEST_METHOD'] Returns the request method used to access the page (such as POST) $_SERVER['REQUEST_TIME'] Returns the timestamp of the start of the request (such as 1377687496) $_SERVER['QUERY_STRING'] Returns the query string if the page is accessed via a query string $_SERVER['HTTP_ACCEPT'] Returns the Accept header from the current request $_SERVER['HTTP_ACCEPT_CHARSET'] Returns the Accept_Charset header from the current request (such as utf-8,ISO-8859-1) $_SERVER['HTTP_HOST'] Returns the Host header from the current request $_SERVER['HTTP_REFERER'] Returns the complete URL of the current page $_SERVER['HTTPS'] Is the script queried through a secure HTTP protocol $_SERVER['REMOTE_ADDR'] Returns the IP address from where the user is viewing the current page $_SERVER['REMOTE_HOST'] Returns the Host name from where the user is viewing the current page
  • 14. 14 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP $_SERVER['REMOTE_PORT'] Returns the port being used on the user's machine to communicate with the web server $_SERVER['SCRIPT_FILENAME'] Returns the absolute pathname of the currently executing script $_SERVER['SERVER_PORT'] Returns the port on the server machine being used by the web server for communication (such as 80) $_SERVER['SERVER_SIGNATURE'] Returns the server version and virtual host name which are added to server-generated pages $_SERVER['PATH_TRANSLATED'] Returns the file system based path to the current script $_SERVER['SCRIPT_NAME'] Returns the path of the current script $_SERVER['SCRIPT_URI'] Returns the URI of the current page GET POST The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character.e.g http://www.test.com/index.htm?nam e1=value1&name2=value2 he POST method transfers information via HTTP headers.e.g http://www.test.com/index.htm It is by default method It is not by default method The GET method is restricted to send upto 1024 characters only. The POST method does not have any restriction on data size to be sent. GET method is not used for password or other sensitive information to be sent to the server. POST method is used for password or other sensitive information to be sent to the server. GET can't be used to send binary data to the server. POST can be used to send binary data to the server. Self Processing Form To combine the HTML document containing the form and PHP script that processes it all into one script
  • 15. 15 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP When user submits the form information by pressing the submit button, the action attribute of the form reference the URL of the same page that displayed in the form This can done by $_SERVER[‘PHP_SELF’] array. <html> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> Name: <input type="text" name="fname"> <input type="submit"> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // collect value of input field } ?> </form> </body> </html> Sticky Forms A sticky form is simply a standard HTML form that remembers how you filled it out. This is a particularly nice feature for end users, especially if you are requiring them to resubmit a form. <html> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> Name: <input type="text" name="fname" value="<?php if (isset($_POST['fname'])) echo $_POST['fname'] ?>"> <input type="submit"> </form> </body>
  • 16. 16 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP </html> Headers function HTTP response that server sends back to a client contains • header that identify the type of content in the body of the response, • The server that sent the response, • How many bytes are in the body, when response was sent etc. This information can be retrieved using header function Syntax header(string,replace,http_response_code) Parameter Description String Required. Specifies the header string to send Replace Optional. Indicates whether the header should replace previous or add a second header. Default is TRUE (will replace). FALSE http_response_code Optional. Forces the HTTP response code to the specified value Possible Parameters of Header 1.Content Type:The content type header identifies the type of document being returned. for e.g for HTML document, it is text/html for plain text it is force the browser to treat the page is specified. <?php header('Content-Type: text/plain');
  • 17. 17 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP ?> 2.Redirection:To sends browser to new URL by setting the location of header <?php header("location:http://www.google.com/"); ?> 3.Expiration:Server can explicitly inform the browser the specified date & time for document to expire. <?php // Date in the past header("Expires: Mon, 26 Jul 2000 05:00:00 GMT"); ?>
  • 18. 18 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP XML What is XML? • XML stands for Extensible Markup Language • XML is a markup language much like HTML • XML is text based markup language that enables to store data in structure format by using meaningful tag. • XML tags are not predefined. You must define your own tags • XML is designed to be self-descriptive • XML is a W3C(World Wide web Consortium) Recommendation Difference Between HTML &XML HTML XML Markup language for displaying web pages in a web browser. Designed to display data with focus on how the data looks Markup language defines a set of rules for encoding documents that can be read by both humans and machines. Designed with focus on storing and transporting data HTML tags are predefined XML tags are not predefined but Custom tags can be created . Display a web page Transport data between the application and the database. No strict rules. Browser will still generate data to the best of its ability Strict rules must be followed or processor will terminate processing the file Search data in HTML is difficult because of predefined tag Search data in XML is easy because of user defined tag. <html> <body> 1 amol </body> <?xml version="1.0" encoding="ISO-8859-1"?> <student > <stud> <rollno>1</rollno> <name>amol</name> </stud>
  • 19. 19 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP </html> </student> Feature of XML 1.XML Separates Data from HTML if you need to display dynamic data in your HTML document, it will take a lot of work to edit the HTML each time the data changes.With XML, data can be stored in separate XML files. This way you can concentrate on using HTML/CSS for display and layout, and be sure that changes in the underlying data will not require any changes to the HTML. With a few lines of JavaScript code, you can read an external XML file and update the data content of your web page. 2 XML Simplifies Data Sharing In the real world, computer systems and databases contain data in incompatible formats. XML data is stored in plain text format. This provides a software- and hardware-independent way of storing data. This makes it much easier to create data that can be shared by different applications. 3.XML Simplifies Data Transport One of the most time-consuming challenges for developers is to exchange data between incompatible systems over the Internet. Exchanging data as XML greatly reduces this complexity, since the data can be read by different incompatible applications. 4. XML Simplifies Platform Changes Upgrading to new systems (hardware or software platforms), is always time consuming. Large amounts of data must be converted and incompatible data is often lost. XML data is stored in text format. This makes it easier to expand or upgrade to new operating systems, new applications, or new browsers, without losing data. 5.XML Makes Your Data More Available
  • 20. 20 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP Different applications can access your data, not only in HTML pages, but also from XML data sources. XML DOCUMENT STRUCTURE OR COMPONENENT OF XML Document Prolog Section Document Prolog comes at the top of the document, before the root element. This section contains − • XML declaration • Document type declaration XML declaration XML declaration contains details that prepare an XML processor to parse the XML document. It is optional, but when used, it must appear in the first line of the XML document. <?xml version = "version_number" encoding = "encoding_declaration" ?> It defines the XML version (1.0) and the encoding information such as ISO-8859-1,UTF-8,UTF- 16 e.g <?xml version="1.0" encoding="ISO-8859-1"?> Document Elements Section Document Elements are the building blocks of XML. Elements can behave as containers to hold text, elements, attributes etc. <element-name attribute1 attribute2> ....content </element-name>
  • 21. 21 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP • element-name is the name of the element. The name its case in the start and end tags must match. A markup construct that begins with < and ends with >. Tags come in three ways • start-tags; for example: <section> • end-tags; for example: </section> • empty-element tags; for example: <section/> • attribute1, attribute2 are attributes of the element separated by white spaces. An attribute defines a property of the element. It associates a name with a value, which is a string of characters. An attribute is written as name=”value” e.g <stud course="bcs"> For e.g 1.a.xml <?xml version="1.0" encoding="ISO-8859-1"?> <student > <stud> <rollno>1</rollno> <name>amol</name> </stud> </student> 2.b.xml <?xml version="1.0" encoding="ISO-8859-1"?> <student> <stud course="bca"> <rollno >1</rollno> <name>amol</name> </stud> <stud course="bcs"> <rollno>2</rollno> <name>amit</name> </stud> </student>
  • 22. 22 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP Where <student>=>It is root element <stud>,<rollno>,<name>=>It is element. course=bcs,course=bca=>Attribute & its value XML Syntax Rules 1 All XML Elements Must Have a Closing Tag In HTML, some elements do not have to have a closing tag: <p>This is a paragraph. <br> In XML, it is illegal to omit the closing tag. All elements must have a closing tag: <p>This is a paragraph.</p> <br /> 2. XML Tags are Case Sensitive XML tags are case sensitive. The tag <Letter> is different from the tag <letter>. Opening and closing tags must be written with the same case: <Message>This is incorrect</message> <message>This is correct</message> 3.XML Elements Must be Properly Nested In HTML, you might see improperly nested elements: <b><i>This text is bold and italic</b></i> In XML, all elements must be properly nested within each other: <b><i>This text is bold and italic</i></b> 4.XML Documents Must Have a Root Element XML documents must contain one element that is the parent of all other elements. This element is called the root element.
  • 23. 23 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP <root> <child> <subchild>.....</subchild> </child> </root> 5.XMLAttribute Values Must be Quoted XML elements can have attributes in name/value pairs just like in HTML. • XML, the attribute values must always be quoted. <student rollno=”1”> <name>amol</name> <address>pune</address> </student> • It doesn’t provide two values for same attribute in the same start tag • Attribute name in XML are case sensitive 6.Comments in XML The syntax for writing comments in XML is similar to that of HTML. <!-- This is a comment --> 7.References: A references allows us to include additional text or markup in an XML document .Reference always begin with the character “&”(Which is specially reserved). And end with the character “;” XML 2 type of reference 1.Entity References: Some characters have a special meaning in XML. If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element.
  • 24. 24 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP There are 5 predefined entity references in XML: &lt; < less than &gt; > greater than &amp; & ampersand &apos; ' Apostrophe &quot; " quotation mark Eg <message>salary < 1000</message> converted into entity refereance <message>salary &lt; 1000</message> 2.Character References: A character reference gives the number of the particular Unicode character it stands for, in either decimal or hexadecimal. Decimal character references look like &#1114; hexadecimal character references have an extra x after the &#;, that is, they look like &#x45A; e.g <data> &#x3C3;&#x3BF;&#x3C6;&#x3CC;&#x3C2; &#x3AD;&#x3B1;&#x3C5;&#x3C4;&#x3CC;&#x3BD; &#x3B3;&#x3B9;&#x3B3;&#x3BD;&#x3CE;&#x3C3;&#x3BA;&#x3B5;&#x3B9; </data> Application of XML 1.Web publishing XML allows the developers to save the data into XML files & use XSLT transformation API’S to generate content in required format such as HTML,XHTML 2.Web Searching It can use XML data & then search the data from the XML file & display to the user 3.Data Transfer It can use XML to save configuration or business data for our application 4.Created Other language Many language are created using XML such as WML
  • 25. 25 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP XML PARASER XML parser to create, read and manipulate an XML document. XML data binding It refers to a means of representing information in an XML document as a business object in computer memory. This allows applications to access the data in the XML from the object rather than using the DOM or SAX to retrieve the data from a direct representation of the XML itself. Or XML data binding is the process of representing information in an XML document as an object in computer memory (deserialization). With XML data binding, applications access XML data direct from the object instead of using the Document Object Model (DOM) to retrieve it from the XML file. Using XML binding, you can integrate XML data into a business rule application. XML PARSER An XML Parser is a parser that is designed to read XMLand create a way for programs to use XML The XML parser defines the properties and methods for accessing and editing XML. All major browsers have a built-in XML parser to access and manipulate XML. 1.xml_parser_create() The xml_parser_create() function creates an XML parser.This function returns a resource handle to be used by other XML functions on success, or FALSE on failure. Syntax xml_parser_create(encoding) 2. xml_parse_into_struct() The xml_parse_into_struct() function parses XML data into an array. This function parses the XML data into 2 arrays: • Value array - containing the data from the parsed XML • Index array - containing pointers to the location of the values in the Value array This function returns 1 on success, or 0 on failure. Syntax xml_parse_into_struct(parser,xml,value_arr,index_arr)
  • 26. 26 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP Parameter Description Parser Required. Specifies XML parser to use Xml Required. Specifies XML data to parse value_arr Required. Specifies the target array for the XML data index_arr Optional. Specifies the target array for index data <?php $xmlfile = 'test.xml'; $xmlparser = xml_parser_create(); fp = fopen($xmlfile, 'r'); $xmldata = fread($fp, 4096); xml_parse_into_struct($xmlparser,$xmldata,$values); xml_parser_free($xmlparser); print_r($values); ?> In PHP there are two major types of XML parsers: 1. SimpleXML SimpleXML is a tree-based parser. SimpleXML is an extension that allows us to easily manipulate and get XML data. SimpleXML provides an easy way of getting an element's name, attributes and textual content if you know the XML document's structure or layout. SimpleXML turns an XML document into a data structure you can iterate through like a collection of arrays and objects.
  • 27. 27 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP SimpleXML function 1.simplexml_load_file() 2.simplexml_load_string() The simplexml_load_file() function loads an XML document into an object. This function returns FALSE on failure. <?php $xml = simplexml_load_file('a.xml'); var_dump($xml); ?> The simplexml_load_string() function loads an XML string into an object. This function returns FALSE on failure. <?php $xmlstring = <<<XML <?xml version="1.0" encoding="ISO-8859-1"?> <student> <stud> <rollno>1</rollno> <name>amol</name> </stud> </student> XML; $xml = simplexml_load_string($xmlstring); var_dump($xml); ?> *4.children() *5. Retrive attribute all nodes The children() function gets the child nodes of the specified XML node. <?php $xml = simplexml_load_file("a.xml"); foreach ($xml->children() as $b) { echo "rollno”.$b->rollno; echo "name”.$b->name; <?php $xml=simplexml_load_file("b.xml"); foreach($xml->children() as $b) { echo $b[0]['course']; echo "<br>"; } ?>
  • 28. 28 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP } ?> 6.simplexml_import_dom() 7. asXML() The simplexml_import_dom() converts a DOM node to a SimpleXMLElement object. This function returns FALSE on failure. <?php $dom = new domDocument; $dom- >loadXML("<stud><name>amol</na me></stud>"); $xml = simplexml_import_dom($dom); echo $xml->name; ?> asXML() It return a well-formed XML string syntax asXML(filename); <?php $xml = simplexml_load_file('a.xml'); header('Content-Type: text/xml'); echo $xml->asXML(); ?> addChild() The addChild() function adds a child element to the SimpleXML element. syntax addChild(name,value); <?php $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><CricketTeam/>'); $s=$xml->addChild('team'); $s->addchild('player','aa');
  • 29. 29 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP header('Content-Type: text/xml'); echo $xml->asXML(); ?> addAttribute() The addAttribute() function adds an attribute to the SimpleXML element. syntax addAttribute(name,value) <?php $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF- 8"?><CricketTeam/>'); $s=$xml->addChild('team'); $s->AddAttribute('country','india'); $s->addchild('player','aa'); header('Content-Type: text/xml'); echo $xml->asXML(); ?> 2.XML DOM • It Is tree based parser
  • 30. 30 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP • DOM is stands for Document Object Model. • It defines a standard way to access and manipulate documents. The Document Object Model (DOM) is a programming API for HTML and XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated. • DOM defines a standard way to access and manipulate XML documents. Dom Function 1. load Loads an XML document from a file. 2.DOMDocument Creates a new DOMDocument object. 3.saveXML Dumps the internal XML tree back into a string 4.loadXML Loads an XML document from a string.7. 5. save It load XML tree into a specified file 6. appendChild() It adds a new child node to the end of the list of children of the node 7. getAttribute() Returns the value of an attribute 8.removeChild() Removes a child node 9.replaceChild() Replace a child node 10. removeAttribute Remove a specified attribute 11. getElementsByTagName Return array with nodes with given tagname in the documenet or empty array if not found
  • 31. 31 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP eg <?php $xd = new DOMDocument(); $xd->load("a.xml"); echo $xd->saveXML(); echo $xd->save(“a.doc”) ?> Display values from xml file <?php $doc=new DOMDocument(); $doc->load("stud.xml"); $bk=$doc->getElementsByTagName("stud"); foreach($bk as $s) { echo "<br>course is".$s->getAttribute("course"); $rn=$s->getElementsByTagName("rollno"); $v1=$rn->item(0)->nodeValue; echo "<br>Rollno is $v1"; $nm=$s->getElementsByTagName("name"); $v2=$nm->item(0)->nodeValue; echo "<br>Name is $v2"; } ?>
  • 32. 32 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP AJAX What is AJAX ? • AJAX stands for Asynchronous JavaScript and XML. • AJAX is about updating parts of a web page, without reloading the whole page. • AJAX is a technique for creating fast and dynamic web pages. • AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page. Asynchronous :The script will send a request to the server, and continue it's execution without waiting for the reply. As soon as reply is received a browser event is fired, which in turn allows the script to execute associated actions A synchronous request blocks the client until operation completes An asynchronous request doesn’t block the client Applications using AJAX Google Maps, Gmail, Youtube, twitter, Facebook
  • 33. 33 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP How AJAX Works
  • 34. 34 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP 1. User sends a request from the UI and a javascript call goes to XMLHttpRequest object. 2. HTTP Request is sent to the server by XMLHttpRequest object. 3. Server interacts with the database using JSP, PHP, Servlet, ASP.net etc. 4. Data is retrieved. 5. Server sends XML data to the XMLHttpRequest callback function. 6. HTML and CSS data is displayed on the browser. 1. The XMLHttpRequest Object The keystone of AJAX is the XMLHttpRequest object. 2. XMLHttpRequest is used for asynchronous communication between client and server It performs following operations: 1. Sends data from the client in the background 2. Receives the data from the server
  • 35. 35 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP 3. Updates the webpage without reloading it. 3. All modern browsers (IE7+, Firefox, Chrome, Safari, and Opera) have a built-in XMLHttpRequest object. 4. Syntax for creating an XMLHttpRequest object: variable=new XMLHttpRequest(); • Old versions of Internet Explorer (IE5 and IE6) uses an ActiveX Object: variable=new ActiveXObject("Microsoft.XMLHTTP"); e.g if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } Methods of XMLHttpRequest object To send a request to a server, we use the open() and send() methods of the XMLHttpRequest object: Syntax open(method,url,async) xmlhttp.send(); Where method: the type of request: GET or POST url: the location of the file on the server
  • 36. 36 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP async: true (asynchronous) or false (synchronous) send() Sends the request to the server (used for GET) send(string) Sends the request to the server (used for POST) eg xmlhttp.open("GET","ajax_info.php",true); Properties of XMLHttpRequest object 1 onreadystatechange It is called whenever readystate attribute changes. 2. readyState It represents the state of the request. It ranges from 0 to 4. 0: request not initialized 1: server connection established 2: request received 3: processing request 4: request finished and response is ready status 200: "OK 404: Page not found 3.Server Response responseText get the response data as a string responseXML get the response data as XML data To get the response from a server, use the responseText or responseXML property of the XMLHttpRequest object.
  • 37. 37 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP e.g xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("t").innerHTML=xmlhttp.responseText; } } Example 1.To display length of string using AJAX <html> <head> <script> function show(str) { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
  • 38. 38 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("t").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","http://localhost/d.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form method="get"> Enter string: <input type="text" onkeyup="show(this.value)"> <br> </form> length is: <span id="t"> </span> </body> </html> d.php <?php $q=$_GET["q"]; $len=strlen($q); echo "length is ".$len; ?>
  • 39. 39 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP 2. To display student details using selected sno Stud(sno,sname,per) <html> <head> <script> function show(str) { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("t").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","http://localhost/d.php?q="+str,true); xmlhttp.send(); } </script>
  • 40. 40 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP </head> <body> <form method="get"> Enter sno: <input type="text" onkeyup="show(this.value)"> <br> </form> student details is: <span id="t"> </span> </body> </html> d.php <?php $q=$_GET["q"]; $con = mysql_connect("localhost", "root", ""); $db= mysql_select_db("bca",$con); $i=0; $sql = "SELECT * from stud where sno=$q"; $res = mysql_query($sql,$con); $cnt = mysql_numrows($res); While($i< $cnt) { echo "<br>sno is ".mysql_result($res,$i,0); echo "<br>name is ".mysql_result($res,$i,1); echo "<br>per is ".mysql_result($res,$i,2); $i++; } mysql_close($con); ?>
  • 41. 41 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP 3 To display book details from XML file b.xml <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book> <title>comp</title> <author>mm</author> <year>2005</year> <price>30.00</price> </book> <book> <title>math</title> <author>nn</author> <year>2005</year> <price>30.00</price> </book> </bookstore> HTML file <html> <head> <script> function show(str) {
  • 42. 42 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("t").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","http://localhost/d.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form method="get"> Enter title: <input type="text" onkeyup="show(this.value)"> <br> </form>
  • 43. 43 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP book details is: <span id="t"> </span> </body> </html> d.php <?php $q=$_GET["q"]; $xml=simplexml_load_file("b.xml"); foreach($xml->children() as $b) { if( $b->title==$q) { echo "title ".$b->title; echo "author ". $b->author; echo "year ".$b->year; echo "price".$b->price; } } ?> 4 To display addition Html file <html> <head> <script> function show() {
  • 44. 44 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP var t1 = document.getElementById('t1').value; var t2= document.getElementById('t2').value; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("t").innerHTML=xmlhttp.responseText; } } var q1= "t1="+t1; var q2="&t2="+t2; xmlhttp.open(“GET”, “http://localhost/d.php?”q1+q2, true);
  • 45. 45 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP xmlhttp.send(); } </script> </head> <body> <form method="get"> Enter no1: <input type="text" id="t1"> <br> Enter no2: <input type="text" id="t2"> <br> <input type="button" value="add" onclick="show()"> </form> addtion is: <span id="t"> </span> </body> </html> d.php <?php
  • 46. 46 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP $a=$_GET['t1']; $b=$_GET['t2']; $c=$a+$b; echo $c; ?> AJAX Advantages AJAX Concept AJAX is not a difficult, you can easy implement AJAX in a meaningful manner. Some IDE are help us to implement AJAX. Speed Reduce the server traffic in both side request. Also reducing the time consuming on both side response. Interaction AJAX is much responsive, whole page(small amount of) data transfer at a time. XMLHttpRequest XMLHttpRequest has an important role in the Ajax web development technique. XMLHttpRequest is special JavaScript object that was designed by Microsoft. XMLHttpRequest object call as a asynchronous HTTP request to the Server for transferring data both side. Asynchronous calls AJAX make asynchronous calls to a web server. This means client browsers are avoid waiting for all data arrive before start the displaying. Form Validation Form are common element in web page. Validation should be instant and properly by using AJAX concept Bandwidth Usage No require to completely reload page again. AJAX is improve the speed and performance.
  • 47. 47 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP AJAX Disadvantages 1 View source is allowed and anyone can view the code source written for AJAX. 2 It can increase design and development time 3 JavaScript disabled browsers cannot use the application. 4 Security is less in AJAX application as all files are downloaded at client side.
  • 48. 48 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP WEB SERVICES What is Web Service? A Web Service is can be defined by following ways: • is a client server application or application component for communication. • method of communication between two devices over network. • is a software system for interoperable machine to machine communication. • is a collection of standards or protocols for exchanging information between two devices or application. Let's understand it by the figure given below: OR A web service is a collection of open protocols and standards used for exchanging data between applications or systems. Software applications written in various programming languages and running on various platforms can use web services to exchange data over computer networks. This interoperability (e.g., between Java and Python, or Windows and Linux applications) is due to the use of open standards. Web Services –Characteristics • XML-based By using XML as the data representation layer for all web services protocols and technologies that are created.
  • 49. 49 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP • Loosely coupled A consumer of a web service is not tied to that web service directly the web service interface can change over time without compromising the client's ability to interact with the service. A tightly coupled system implies that the client and server logic are closely tied to one another, implying that if one interface changes, the other must also be updated. Adopting a loosely coupled architecture tends to make software systems more manageable and allows simpler integration between different systems. • Ability to be Synchronous or Asynchronous Synchronicity refers to the binding of the client to the execution of the service. In synchronous invocations, the client blocks and waits for the service to complete its operation before continuing. Asynchronous operations allow a client to invoke a service and then execute other functions. • Supports Remote Procedure Calls(RPCs) Web services allow clients to invoke procedures, functions, and methods on remote objects using an XML-based protocol. • Supports Document Exchange One of the key advantages of XML is its generic way of representing not only data, but also complex documents. These documents can be as simple as representing a current address, or they can be as complex as representing an entire book or Request for Quotation (RFQ). Web services support the transparent exchange of documents to facilitate business integration. • Platform-independence It is platform independence • Language-independence It is language independence Web Services - Architecture There are two ways to view the web service architecture:
  • 50. 50 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP • The first is to examine the individual roles of each web service actor. • The second is to examine the emerging web service protocol stack. Web Service Roles There are three major roles within the web service architecture: Service Provider This is the provider of the web service. The service provider implements the service and makes it available on the Internet. Service Requestor This is any consumer of the web service. The requestor utilizes an existing web service by opening a network connection and sending an XML request. Service Registry This is a logically centralized directory of services. The registry provides a central place where developers can publish new services or find existing ones. It therefore serves as a centralized clearing house for companies and their services. Web Service Protocol Stack
  • 51. 51 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP A second option for viewing the web service architecture is to examine the emerging web service protocol stack. The stack is still evolving, but currently has four main layers. Service Transport This layer is responsible for transporting messages between applications. Currently, this layer includes Hyper Text Transport Protocol (HTTP), Simple Mail Transfer Protocol (SMTP), File Transfer Protocol (FTP), and newer protocols such as Blocks Extensible Exchange Protocol (BEEP). XML Messaging This layer is responsible for encoding messages in a common XML format so that messages can be understood at either end. Currently, this layer includes XML-RPC and SOAP. Service Description This layer is responsible for describing the public interface to a specific web service. Currently, service description is handled via the Web Service Description Language (WSDL). Service Discovery This layer is responsible for centralizing services into a common registry and providing easy publish/find functionality. Currently, service discovery is handled via Universal Description, Discovery, and Integration (UDDI). As web services evolve, additional layers may be added and additional technologies may be added to each layer. Web Service Components
  • 52. 52 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP There are three major web service components. 1. SOAP 2. WSDL 3. UDDI 1 WSDL • WSDL stands for Web Services Description Language. • WSDL was developed jointly by Microsoft and IBM. • WSDL is used to describe web services • WSDL is written in XML • WSDL definition describes how to access a web service and what operations it will perform. • Web services and describes how service providers and requesters communicate with one another. WSDL Documents An WSDL document describes a web service. It specifies the location of the service, and the methods of the service, using these major elements: Element Description <types> Defines the (XML Schema) data types used by the web service <message> Defines the data elements for each operation <portType> Describes the operations that can be performed and the messages involved. Type Definition One-way The operation can receive a message but will not return a response Request-response The operation can receive a request and will return a response Solicit-response The operation can send a request and will wait for a response Notification The operation can send a message but will not
  • 53. 53 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP wait for a response <binding> Defines the protocol and data format for each port type The main structure of a WSDL document looks like this: <definitions> <types> data type definitions........ </types> <message> definition of the data being communicated.... </message> <portType> set of operations...... </portType> <binding> protocol and data format specification.... </binding> </definitions> e.g <message name="getTermRequest"> <part name="term" type="xs:string"/> </message> <message name="getTermResponse"> <part name="value" type="xs:string"/> </message> <portType name="glossaryTerms"> <operation name="getTerm"> <input message="getTermRequest"/>
  • 54. 54 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP <output message="getTermResponse"/> </operation> </portType> <binding type="glossaryTerms" name="b1"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <operation> <soap:operation soapAction="http://example.com/getTerm"/> <input><soap:body use="literal"/></input> <output><soap:body use="literal"/></output> </operation> </binding> Where <portType> element defines "glossaryTerms" as the name of a port, and "getTerm" as the name of an operation. The "getTerm" operation has an input message called "getTermRequest" &output message called "getTermResponse". The <message> elements define the parts of each message and the associated data types The binding element has two attributes - name and type. The name attribute (you can use any name you want) defines the name of the binding, and the type attribute points to the port for the binding, in this case the "glossaryTerms" port. The soap:binding element has two attributes - style and transport. The style attribute can be "rpc" or "document". In this case we use document. The transport attribute defines the SOAP protocol to use. In this case we use HTTP. The operation element defines each operation that the portType exposes. For each operation the corresponding SOAP action has to be defined. You must also specify how the input and output are encoded. In this case we use "literal". 2 SOAP
  • 55. 55 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP SOAP is an XML-based protocol for exchanging information between computers. • SOAP is a communication protocol. • SOAP is for communication between applications. • SOAP is a format for sending messages. • SOAP is designed to communicate via Internet. • SOAP is platform independent. • SOAP is language independent. • SOAP is simple and extensible. • SOAP allows you to get around firewalls. • SOAP will be developed as a W3C standard. A SOAP message is an ordinary XML document containing the following elements: An Envelope element that identifies the XML document as a SOAP message A Header element that contains header information A Body element that contains call and response information A Fault element containing errors and status information <?xml version="1.0"?> <soap: Envelope xmlns: soap="http://www.w3.org/2001/12/soap-envelope"soap: encodingStyle="http://www.w3.org/2001/12/soapencoding"> <soap:Header> ... ---------- </soap:Header> <soap:Body> ...<soap:Fault> ... </soap:Fault> </soap:Body> </soap:Envelope>
  • 56. 56 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP 3.UDDI • UDDI stands for Universal Description, Discovery, and Integration. • UDDI is an XML-based standard for describing, publishing, and finding web services. • UDDI, defines the standard interfaces and mechanisms for registries intended for publishing and storing descriptions of network services in terms of XML messages. • Web services model, UDDI provides the registry for Web services to function as the service providers to populate the registry with service descriptions and service types and the service requestors to query the registry to find and locate the services. It enables Web applications to interact with a UDDI-based registry using SOAP messages. T • A UDDI registry can be in two modes public mode and private mode • A public UDDI registry is available for everyone to publish/query the business and service information on the Internet. • A private UDDI registry is operated by a single organization or a group of collaborating organizations to share the information that would be available only to the participating bodies. • Businesses can use a UDDI registry at three levels:-
  • 57. 57 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP 1.White Pages White pages give information about the business supplying the service. This includes the name of the business and a description of the business - potentially in multiple languages. Using this information, it is possible to find a service. 2.Yellow pages Businesses that intend to classify their information based on categorizations (also known as classification schemes or taxonomies) make use of the UDDI registry as yellow pages.. 3.Green Pages Green pages are used to describe how to access a Web Service, with information on the service bindings. Some of the information is related to the Web Service - such as the address of the service and the parameters, and references to specifications of interfaces. XML-RPC(Remote Procedure Call) • This is the simplest XML-based protocol for exchanging information between computers. • RPC stands for Remote Procedure Call. As its name indicates, it is a mechanism to call a procedure or a function available on a remote computer • XML-RPC is a simple protocol that uses XML messages to perform RPCs. • Requests are encoded in XML and sent via HTTP POST. • XML responses are embedded in the body of the HTTP response. • XML-RPC is platform-independent. • XML-RPC allows diverse applications to communicate. • XML-RPC's most obvious field of application is connecting different kinds of environments, allowing Java to talk with Perl, Python, ASP, and so on. • XML-RPC permits programs to make function or procedure calls across a network. • XML-RPC uses the HTTP protocol to pass information from a client computer to a server computer. • XML-RPC uses a small XML vocabulary to describe the nature of requests and responses. • XML-RPC client specifies a procedure name and parameters in the XML request, and the server returns either a fault or a response in the XML response. • XML-RPC parameters are a simple list of types and content - structs and arrays are the most complex types available.
  • 58. 58 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP • XML-RPC has no notion of objects and no mechanism for including information that uses other XML vocabulary. • XML-RPC consists of three relatively small parts: • XML-RPC data model : A set of types for use in passing parameters, return values, and faults (error messages). • XML-RPC request structures : An HTTP POST request containing method and parameter information. • XML-RPC response structures : An HTTP response that contains return values or fault information.
  • 59. 59 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP PHP FRAMEWORK What is PHP Framwork? A framework, or software framework, is a platform for developing software applications. It provides a foundation on which software developers can build programs for a specific platform. A framework may also include code libraries, a compiler, and other programs used in the software development process. List of Framework • Joomla • Drupal • Word press • CakePHP. ... • Zend Framework. ... • Symfony • Seagull • Yii. Advantages PHP Frameworks 1.Speed up custom web application development Nowadays, PHP programmers have to write web applications based on complex business requirements. Likewise, they have to explore ways to make the web application deliver richer user experience. The tools, features, and code snippets provided by PHP frameworks help developers to accelerate custom web application development. 2. Simplify web application maintenance Unlike other programming languages, PHP does not emphasize on code readability and maintainability. The PHP frameworks simplify web application development and maintenance by supporting model-view-controller (MVC) architecture. The developers can take advantage of MVC architecture to divide a web application into models, views and controllers. They can use a
  • 60. 60 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP MVC framework for PHP to keep the application’s user interface and business logic layers separated. 3. No need to write additional code PHP, unlike other programming languages, does not allow programmers to express concepts without writing longer lines of code. Hence, the PHP programmers have to write lengthy and complex code while adding features or functionality to a website. The PHP frameworks reduce coding time significantly by providing code generation feature. The code generation features provided by certain PHP frameworks enable programmers to keep the source code of web application clean and maintainable. 4. Work with databases more efficiently Most PHP frameworks allow programmers to work with a number of widely used relational databases. 5. Automate common web development tasks While building a web application, developers have to perform a number of tasks in addition to writing code. Some of these common web development tasks require programmers to invest additional time and effort. The functions and tools provided by PHP frameworks help developers to automate common web development tasks like caching, session management, authentication, and URL mapping. 6.Protect websites from targeted security attacks The built-in security features and mechanisms provided by PHP framework make it easier for developers to protect the website from existing and emerging security threats 7.Perform unit testing efficiently PHP frameworks support PHPUnit natively, and enable programmers to perform unit testing smoothly 8.No need to increase web development cost
  • 61. 61 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP The developers also have option to choose from several open source web frameworks for PHP. They can even available the features and tools provided by these open source PHP frameworks speed up custom web application development without increasing project overheads. Joomla Framework 1. Joomla is an open source Content Management System (CMS), which is used to build websites and online applications. 2. The Content Management System (CMS) is a software which keeps track of the entire data (such as text, photos, music, documents, etc.) which will be available on your website. It helps in editing, publishing and modifying the content of the website. 3. It is free and extendable which is separated into front-end and back-end templates (administrator). 4. Joomla is uses PHP &MySQL (used for storing the data). 5. 4. It support MVC architecture Drupal Framework 1. Drupal is an open source Content Management System (CMS).It offeres flexibility in design through simplicity. 2. Drupal uses LAMP server L:Linux (Operating system)
  • 62. 62 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP A:Appache(Web Server) M:MySQL(Data Storage) P:PHP(Programming Lang) 4. It support MVC architecture 3.The architecture of Drupal contains the following layers • Users • Administrator • Drupal • PHP • Web Server • Database
  • 63. 63 Vision Academy (9822506209/9823037693) (SACHIN SIR MCS In Scientific Computing From ISSC,UOP,SET ) Classes For BBa(CA)/BCA/BCS/MCS/MCA/MCS/Dip(Comp/IT)/BE(Comp/IT) PHP Application • Government Application • Small Business web portal • Online System for reservation, media related web site etc Contact: Vision Academy Since 2005 Prof. Sachin Sir(MCS,SET) 9822506209/9823037693 www.visionacademe.com Branch1:Nr Sm Joshi College,Abv Laxmi zerox,Ajikayatara Build,Malwadi Rd,Hadapsar Branch2:Nr AM College,Aditya Gold Society,Nr Allahabad Bank ,Mahadevnager