Professional Documents
Culture Documents
(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
Object
It is instance of class
<?php
class phpClass
{
var $var1;
var $var2 = "constant string";
}
……
……
}
?>
<?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
}
}
$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.
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.
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
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
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.
<?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
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
$_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
Returns the filename of the currently executing
$_SERVER['PHP_SELF']
script
Returns the version of the Common Gateway
$_SERVER['GATEWAY_INTERFACE']
Interface (CGI) the server is using
$_SERVER['SERVER_ADDR'] Returns the IP address of the host server
Returns the name of the host server (such as
$_SERVER['SERVER_NAME']
www.vision.com)
Returns the server identification string (such as
$_SERVER['SERVER_SOFTWARE']
Apache/2.2.24)
Returns the name and revision of the information
$_SERVER['SERVER_PROTOCOL']
protocol (such as HTTP/1.1)
GET POST
The GET method sends the encoded user he POST method transfers information via HTTP
information appended to the page headers.e.g
request. The page and the encoded
information are separated by the ?
character.e.g
http://www.test.com/index.htm
http://www.test.com/index.htm?nam
e1=value1&name2=value2
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
<html>
<body>
<?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.
Syntax
header(string,replace,http_response_code)
Parameter Description
String Required. Specifies the header string to send
Optional. Indicates whether the header should replace previous or add a
Replace
second header. Default is TRUE (will replace). FALSE
http_response_code Optional. Forces the HTTP response code to the specified value
<?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
?>
header("location:http://www.google.com/");
?>
<?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
amol <name>amol</name>
</body> </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
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.
Different applications can access your data, not only in HTML pages, but also from XML data
sources.
• 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.
Document Elements are the building blocks of XML. Elements can behave as containers to hold
text, elements, attributes etc.
• 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
For e.g
1.a.xml
2.b.xml
Where
<stud>,<rollno>,<name>=>It is element.
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
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
“;”
1.Entity References:
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
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 њ hexadecimal character references
have an extra x after the &#;, that is, they look like њ
e.g
<data>
σοφός
έαυτόν
γιγνώσκει
</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.
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()
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
value_arr Required. Specifies the target array for the XML 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);
?>
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 The simplexml_load_string() function loads an XML string
loads an XML document into an into an object.
object. This function returns FALSE on failure.
This function returns FALSE on <?php
failure.
$xmlstring = <<<XML
<?php
<?xml version="1.0" encoding="ISO-8859-1"?>
$xml = simplexml_load_file('a.xml');
<student>
var_dump($xml);
<stud>
?>
<rollno>1</rollno>
<name>amol</name>
</stud>
</student>
XML;
$xml = simplexml_load_string($xmlstring);
var_dump($xml);
?>
}
?>
6.simplexml_import_dom() 7. asXML()
syntax
addChild(name,value);
<?php
$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()
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 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.
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
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.
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");
}
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
eg
xmlhttp.open("GET","ajax_info.php",true);
1 onreadystatechange
status
200: "OK
3.Server Response
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()
document.getElementById("t").innerHTML=xmlhttp.responseText;
Example
<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
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>
d.php
<?php
$q=$_GET["q"];
$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
b.xml
<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
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;
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange=function()
document.getElementById("t").innerHTML=xmlhttp.responseText;
var q2="&t2="+t2;
xmlhttp.send();
</script>
</head>
<body>
<form method="get">
Enter no1:
<br>
Enter no2:
<br>
</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.
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
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.
• 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.
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.
Web services allow clients to invoke procedures, functions, and methods on remote
objects using an XML-based protocol.
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
• The first is to examine the individual roles of each web service actor.
• The second is to examine the emerging web service protocol stack.
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.
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.
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
Type Definition
The operation can receive a message but will
<portType> One-way
not return a response
The operation can receive a request and will
Request-response
return a response
The operation can send a request and will wait
Solicit-response
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
<binding> Defines the protocol and data format for each port type
<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>
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 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 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
<?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
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
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.
• 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
for a specific platform. A framework may also include code libraries, a compiler,
List of Framework
• Joomla
• Drupal
• Word press
• CakePHP. ...
• Zend Framework. ...
• Symfony
• Seagull
• Yii.
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.
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.
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.
Most PHP frameworks allow programmers to work with a number of widely used relational
databases.
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.
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
PHP frameworks support PHPUnit natively, and enable programmers to perform unit testing
smoothly
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).
Drupal Framework
A:Appache(Web Server)
M:MySQL(Data Storage)
P:PHP(Programming Lang)
• 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
Contact: