0% found this document useful (0 votes)
34 views28 pages

WP Lab Manual

This document outlines a web programming course led by Prof. Devanshi Dave, detailing a series of experiments aimed at teaching HTML, CSS, JavaScript, and PHP. The experiments include creating a resume, class timetable, static web pages, and a REST API, focusing on various web development techniques and best practices. Each experiment includes objectives, theoretical background, and practical coding examples to reinforce learning.

Uploaded by

Devanshi Dave
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views28 pages

WP Lab Manual

This document outlines a web programming course led by Prof. Devanshi Dave, detailing a series of experiments aimed at teaching HTML, CSS, JavaScript, and PHP. The experiments include creating a resume, class timetable, static web pages, and a REST API, focusing on various web development techniques and best practices. Each experiment includes objectives, theoretical background, and practical coding examples to reinforce learning.

Uploaded by

Devanshi Dave
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Web Programming (3160713) PROF.

DEVANSHI DAVE

Index

Sr. Objective(s) of Experiment


No.

Create your resume using HTML (Suggested sections of resume are Personal
Information, Educational Information, Professional Skills, Experience,
1. Achievements, Hobbies),
Experiment with text, colors, link and lists.
Create your class time table using table tag, experiment with rowspan,
2. colspan,
cellspacing and cellpadding attributes.
Design static web pages for your college containing a description of the courses,
departments, faculties, library etc. Provide
3.
links for navigation among pages.

Design a web page of your home town with an attractive background color, text
4. color, an
Image, font etc. (use internal CSS).
Use Inline CSS to format your resume that
5.
you created in practical no 01.
Use External, Internal, Inline CSS to format
6. College Web site that you created in Practical No.03

7. Develop a java script to display today’s date.

Develop simple calculator for addition, subtraction, multiplication and


8. division
operation using java script.
9. Write a PHP program to check if number is
prime or not.
10. Create a REST API using php.

1
Web Programming (3160713) PROF. DEVANSHI DAVE

Experiment No: 1

Create your resume using HTML (Suggested sections of resume are Personal
Information, Educational Information, Professional Skills, Experience,
Achievements, Hobbies), Experiment with text, colors, link and lists.

Date:

Competency and Practical Skills:

Relevant CO: 1

Objectives:

1. To understand HTML Page Structure.


2. To understand how to use HTML tag attributes.

Theory:

HTML:

- HTML stands for Hypertext Markup Language


- It is used to display the document in the web browser
- Hypertext is simply a piece of text that works as a link
- Markup Language is a way of writing layout information within documents
HTML Document Structure

- HTML Document consists of three main parts


o DOCTYPE declaration
o <head> section
o <body> section

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1> Hello World </h1>
</body>
</html>

DOCTYPE specifies the document type. the document type is specified by the Document Type
Definition (DTD).

- <head> section is used to specify title of the page using <title> tag. It is also used for
adding external css and javascript files to html document.

2
Web Programming (3160713) PROF. DEVANSHI DAVE

How to save and check output

- Editors like notepad, notepad++, sublime text, visual studio code can be used to write html
code
- Save html document file with .html extension
- To check output open html document with browser like google chrome, Microsoft edge,
Firefox etc.
HTML Formatting Tags

- <b>text </b>- for making the text bold.


- <strong> text</strong>- for making the text Important text
- <i>text </i>- for making the text Italic text
- <em>text </em>- to make the Emphasized text
- <mark>text</mark>- to make the text Marked text
- <small>text </small>- to make the text Smaller text
- <del>text</del> - to make the text Deleted text
- <ins>text </ins>- to make the text Inserted text
- <sub>text <sub>- to make the text Subscript text
- <sup>text</sup>- to make the text Superscript text
- <h1> to <h6> tags – for making Headings
- Font Color (<font color=” red”>Hello</font>) – to change font color
- Font Size (<font size=”10px”>Hello</font>) – to change font size

HTML List Tag

- HTML List allow web developers to group a set of related items in lists

- Unordered HTML List

o Starts with <ul> tag list item starts with <li> tag
o Lists items will be marked with bullets
o Example

<ul>
<li>C</li>
<li>C++</li>
<li>Java</li>
</ul>

- Ordered HTML List

3
Web Programming (3160713) PROF. DEVANSHI DAVE
o Starts with <ol> tag. Each list item starts with the <li> tag.
o Lists items will be marked with numbers by default

<ol>
<li>Apple</li>
<li>Mango</li>
<li>Banana</li>
</ol>

- HTML Description Lists

o A description list is a list of terms with a description of each term.

<dl>
<dt>CE</dt>
<dd>- Computer Engineering</dd>
<dt>IT</dt>
<dd>- Information Technology</dd>
</dl>
o <dl> tag defines the description list,<dt> tag defines the term (name) <dd> tag
describes each term

4
Web Programming (3160713) PROF. DEVANSHI DAVE
Experiment No: 2

Create your class time table using table tag, experiment with rowspan, colspan,
cellspacing and cellpadding attributes.

Date:

Competency and Practical Skills:

Relevant CO: 1

Objectives:

1. To study HTML table tag


2. To study how to organize data in tabular format
Theory:

HTML Table Tag

- HTML tables allow web developers to arrange data into rows and columns.
- The <table> tag defines an HTML table.
- table row is defined with a <tr> tag.
- table header is defined with a <th> tag.
- text in <th> elements are bold and centered.
- Each table data/cell is defined with a <td>.
- By default, the text in <td> elements are regular and left-aligned.
- colspan attribute is used to make a cell span more than one column.
- Rowspan attriute is used to make a call span more than one row.
- cellpadding represents the distance between cell borders and the content within a cell.
- The cellspacing attribute defines space between table cells.
- Example
o Below code is for arranging car details in tabular format.
o You may study table tag and output as below.

5
Web Programming (3160713) PROF. DEVANSHI DAVE

Code Output

<table border="1">
<tr>
<th>Name</th>
<th>Color</th>
<th>Price</th>
</tr>
<tr>
<td>Swift VXI</td>
<td>Red</td>
<td>800000</td>
</tr>
<tr>
<td>Vagon R</td>
<td>White</td>
<td>600000</td>
</tr>
</table>

6
Web Programming (3160713) PROF. DEVANSHI DAVE
Experiment No: 3

Design static web pages for your college containing a description of the courses,
departments, faculties, library etc. Provide links for navigation among pages.

Date:

Competency and PracticalSkills:

Relevant CO: 1

Objectives:

1. To study HTML Link.

Theory:

HTML Links:

- Links allow users to click their way from page to page.


- User can click on a link and jump to another document.
- When you move the mouse over a link, the mouse arrow will turn into a little hand.
- Syntax
o <a href="url"> link text </a>
- Example
<a href=http://www.gtu.ac.in / target=”_blank”>Visit GTU</a>
- links will appear as follows in all browsers:
o An unvisited link is underlined and blue
o A visited link is underlined and purple
o An active link is underlined and red
- HTML Link Taget Attribute
o By default, the linked page will be displayed in the current browser window. To
change this, you must specify another target for the link.
o The target attribute specifies where to open the linked document.
o The target attribute can have one of the following values:
▪ _self - Default. Opens the document in the same window/tab as it was
clicked
▪ _blank - Opens the document in a new window or tab
▪ _parent - Opens the document in the parent frame
▪ _top - Opens the document in the full body of the window

7
Web Programming (3160713) PROF. DEVANSHI DAVE

Experiment No: 4

Design a web page of your home town with an attractive background color,
text color, an Image, font etc. (use internal CSS).

Date:

Competency and Practical Skills:

Relevant CO: 1

Objectives:

1. To understand how CSS works.

Theory:

Introduction To CSS

- CSS stands for Cascading Style Sheets


- CSS describes how HTML elements are to be displayed.
- CSS saves a lot of work. It can control the layout of multiple web pages all at once
- External stylesheets are stored in CSS files
- HTML was NEVER intended to contain tags for formatting a web page! HTML was
created to describe the content of a web page.
- When tags like <font>, and color attributes were added to the HTML 3.2 specification, it
started a nightmare for web developers. Development of large websites, where fonts and
color information were added to every single page, became a long and expensive process.
- To solve this problem, the World Wide Web Consortium (W3C) created CSS.
- CSS removed the style formatting from the HTML page!
CSS Syntax

- A CSS rule-set consists of a selector and a declaration block:


- The selector points to the HTML element you want to style.
- The declaration block contains one or more declarations separated by semicolons.
- Each declaration includes a CSS property name and a value, separated by a colon.
- declaration blocks are surrounded by curly braces.

Example: In this example all <p> elements will be center-aligned, with a red text color

Code Output
8
Web Programming (3160713) PROF. DEVANSHI DAVE

<!DOCTYPE html>
<html>
<head>
<style>
p{
color: red;
text-align: center;
}
</style>
</head>
<body>
<p>Hello World!</p>
<p>These paragraphs are styled
with CSS.</p>
</body>
</html>

- p is a selector in CSS (it points to the HTML element you want to style: <p>).
- color is a property, and red is the property value
- text-align is a property, and center is the property value
CSS Selectors

- CSS Element Selector


o The element selector selects HTML elements based on the element name.
o Example:

p{
text-align: center;
color: red;
}

- The CSS id Selector

o The id selector uses the id attribute of an HTML element to select a specific


element.
o The id of an element is unique within a page, so the id selector is used to select one
unique element!
o To select an element with a specific id, write a hash (#) character, followed by the
id of the element.
o Example

9
Web Programming (3160713) PROF. DEVANSHI DAVE

<!DOCTYPE html>
<html>
<head>
<style>
#para1 {
text-align: center;
color: red;
}
</style>
</head>
<body>
<p id="para1">Hello World!</p>
<p>This paragraph is not affected by
the style.</p>
</body>
</html>

- CSS Class Selector

o The class selector selects HTML elements with a specific class attribute.
o To select elements with a specific class, write a period (.) character, followed by
the class name.
o Example
▪ In this example all HTML elements with class="center" will be red and
center-aligned:
<!DOCTYPE html>
<html>
<head>
<style>
.center {
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1 class="center">Red and center-
aligned heading</h1>
<p class="center">Red and center-
aligned paragraph.</p>
</body>
</html>

- CSS Universal Selector

o The universal selector (*) selects all HTML elements on the page.
o Example
-

10
Web Programming (3160713) PROF. DEVANSHI DAVE

<!DOCTYPE html>
<html>
<head>
<style>
*{
text-align: center;
color: blue;
}
</style>
</head>
<body>
<h1>Hello world!</h1>
<p>Every element on the page will be
affected by the style.</p>
<p id="para1">Me too!</p>
<p>And me!</p>
</body>
</html>

- CSS Grouping Selector

o The grouping selector selects all the HTML elements with the same style
definitions.
o To group selectors, separate each selector with a comma.
o Example:

h1, h2, p {
text-align: center;
color: red;
}

- The CSS Pseudo Class Selector

o Some selectors can be considered different because of the way the element they
belong to works.
o For example, the anchor that creates a link between documents can have pseudo
classes attached to it simply because it is not known at the time of writing the
markup what the state will be.
o It could be visited, not visited, or in the process of being selected.
o CSS pseudo-classes are used to add special effects to some selectors. You do not
need to use JavaScript or any other script to use those effects.
o selector: pseudo-class {property: value}
o CSS classes can also be used with pseudo-classes
o selector.class: pseudo-class {property: value}
o Example

11
Web Programming (3160713) PROF. DEVANSHI DAVE

a : link { color: red} o


a : active { color: yellow}
a : visited { color: green}
a : hover { font-weight: bold}
a : link : hover {font-weight:bold}

- Types Of CSS

o External CSS
o Internal CSS
o Inline CSS
- Internal CSS

o An internal style sheet may be used if one single HTML page has a unique style.
o The internal style is defined inside the <style> element, inside the head section.
o Example:

<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>

-CSS Background Color

- The background-color property specifies the background color of an element.


- With CSS, a color is most often specified by:
o a valid color name - like "red"
o a HEX value - like "#ff0000"
o an RGB value - like "rgb (255,0,0)"
Example:

12
Web Programming (3160713) PROF. DEVANSHI DAVE

body {
background-color: lightblue;
}

-CSS Text Color

- text color can be set using color property


Example:

<h1 style="color:Tomato;">Hello
World</h1>

13
Web Programming (3160713) PROF. DEVANSHI DAVE
Experiment No: 5

Use Inline CSS to format your resume that you created in practical no 01.

Date:

Competency and PracticalSkills:

Relevant CO: 1

Objectives:

1. To understand the use of Inline CSS.


Theory:

Internal CSS

- An inline style may be used to apply a unique style for a single element.
- To use inline styles, add the style attribute to the relevant element. The style attribute can
contain any CSS property.
Example:

<!DOCTYPE html>
<html>
<body>
<h1 style="color:blue;text-align:center;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
</body>
</html>

14
Web Programming (3160713) PROF. DEVANSHI DAVE
Experiment No: 6

Use External, Internal, Inline CSS to format College Web site that you created
in Practical No.03

Date:

Competency and PracticalSkills:

Relevant CO: 1

Objectives:

1. To understand use of External CSS


Theory:

External CSS

• An external file is a good idea when you have a number of pages, or even a complete site,
which you need to control in terms of presentation.
• it saves lots of effort as at one time you would have needed to alter each page individually.
• With an external style sheet, you can change the look of an entire website by changing just
one file!
• Each HTML page must include a reference to the external style sheet file inside the <link>
element, inside the head section.
• External CSS file must be saved with a .css extension.
• Example

HTML Code : index.html

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
type="text/css" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>

CSS Code : mystyle.css

15
Web Programming (3160713) PROF. DEVANSHI DAVE

body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}

16
Web Programming (3160713) PROF. DEVANSHI DAVE
Experiment No: 7

Develop a java script to display today’s date.

Date:

Competency and PracticalSkills:

Relevant CO: 2

Objectives:

1. To understand how to write simple java script


Theory:

Javascript

• Javascript is a client side scripting language.


• HTML and CSS for static rendering of a page
• Scripting languages allows content to change dynamically
• Possible to interact with the user beyond what is possible with HTML
• Scripts are programs and can execute on the client side (the one with the browser) or
server.
• Running a script on the client saves processing time on the server
• Types Of Javascript

o Internal Javascript
▪ JavaScript code is placed in the head and body section of an HTML page.
▪ Example

<html>
<head>
<title>Internal JavaScript</title>
<script type="text/javascript">
document.write("Hello World.!!!");
</script>
</head>
<body>
</body>
</html>

o External JavaScript
▪ If you want to use the same script on several pages it could be good idea to
place the code in separate file, rather than writing it on each.
▪ JavaScript code are stored in separate external file using the .js extension
(Ex: external.js).

17
Web Programming (3160713) PROF. DEVANSHI DAVE
▪ Example:
HTML File : index.html

<html>
<head>
<title>External JavaScript</title>
<script type="text/javascript" src="external.js"></script>
</head>
<body>
</body>
</html>

External JavaScript file : external.js

document.write("This is External Javascript Example.!!!");

18
Web Programming (3160713) PROF. DEVANSHI DAVE
Experiment No: 8

Develop simple calculator for addition, subtraction, multiplication and division


operation using java script.

Date:

Competency and Practical Skills:

Relevant CO: 2

Objectives:

1. To understand the use of mathematical operators in javascript.

2. To understand the use of document object model.

3. To understand javascript event handling.

Theory:

Javascript Syntax

How to create and use variables?

varx,y,z;

x=5;

y=5

z=x+y;

document.write(“total is : ”+z)

The HTML DOM (Document Object Model)

- When a web page is loaded, the browser creates a Document Object Model of the page.
- The HTML DOM model is constructed as a tree of Objects:
- Using DOM Javascript can
o change all the HTML elements in the page
o change all the HTML attributes in the page

19
Web Programming (3160713) PROF. DEVANSHI DAVE
o change all the CSS styles in the page
o remove existing HTML elements and attributes
o add new HTML elements and attributes
o react to all existing HTML events in the page
o create new HTML events in the page

Figure 1 Document Object Model

DOM Examples

Example 1: following example changes the content of <p> element

<html>
<body>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = "Hello World!";
</script>

</body>
</html>

20
Web Programming (3160713) PROF. DEVANSHI DAVE
Here getElementById is a method, while innerHTML is a property.

Example 2: Validate Numeric Input

<!DOCTYPE html>
<html>
<body>

<h2>Number Validation</h2>

<p>Enter a number between 1 and 10:</p>

<input id="numb">

<button type="button" onclick="myFunction()">Submit</button>

<p id="demo"></p>

<script>
function myFunction() {
// Get the value of the input field with id="numb"
let x = document.getElementById("numb").value;
// If x is Not a Number or less than one or greater than 10
let text;
if (isNaN(x) || x < 1 || x > 10) {
text = "Input not valid";
} else {
text = "Input OK";
}
document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>

21
Web Programming (3160713) PROF. DEVANSHI DAVE
Experiment No: 9

Write a PHP program to check if number is prime or not.

Date:

Competency and Practical Skills:

Relevant CO: 3

Objectives:

1. To understand how to write simple php program


2. To understand how to use php conditional and Loops Statement
Theory:

PHP

• PHP is a server scripting language, and a powerful tool for making dynamic and
interactive Web pages.
• PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's
ASP.
• Syntax

<?php
// PHP code goes here
?>

• Example:demonstrate printing Hello World

<!DOCTYPE html>
<html>
<body>

<?php
echo "Hello World";
?>
</body>
</html>

• Creating (Declaring) PHP Variables

<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>

22
Web Programming (3160713) PROF. DEVANSHI DAVE

• PHP Conditional Statements

Statement Syntax

PHP - The if Statement


if (condition) {
code to be executed if
condition is true;
}
PHP - The if...else Statement
if (condition) {
code to be executed if
condition is true;
} else {
code to be executed if
condition is false;
}
PHP - The if...elseif...else Statement
if (condition) {
code to be executed if
this condition is true;
} elseif (condition) {
code to be executed if
first condition is false
and this condition is
true;
} else {
code to be executed if
all conditions are false;
}

• PHP Loop Statements

Statement Syntax

The PHP while Loop


while (condition is true)
{
code to be executed;
}
The PHP do...while Loop
do {
code to be executed;
} while (condition is
true);

23
Web Programming (3160713) PROF. DEVANSHI DAVE
The PHP for Loop
for (init counter; test
counter; increment
counter) {
code to be executed for
each iteration;
}
The PHP foreach Loop
foreach
($array as $value) {
code to be executed;
}

Conclusion:

The PHP program efficiently checks whether a given number is prime or not using PHP's
conditional statements and loops. This practical exercise enhances understanding of PHP syntax
and its application in solving mathematical problems on the web

24
Web Programming (3160713) PROF. DEVANSHI DAVE
Experiment No: 10

Create a REST API using php.

Date:

Competency and Practical Skills:

Relevant CO: 5

Objectives:

1. To understand how REST API works.


Theory:

What is REST?
REST stands for Representational State Transfer, REST is an architectural style which defines
a set of constraints for developing and consuming web services through standard protocol
(HTTP). REST API is a simple, easy to implement and stateless web service. There is another
web service available which is SOAP which stands for Simple Object Access Protocol which is
created by Microsoft.

REST API is widely used in web and mobile applications as compared to SOAP. REST can
provide output data in multiple formats such as JavaScript Object Notation (JSON), Extensible
Markup Language (XML), Command Separated Value (CSV) and many others while SOAP
described output in Web Services Description Language (WSDL).
How Does REST API Work
REST requests are related to CRUD operations (Create, Read, Update, Delete) in database, REST
uses GET, POST, PUT and DELETE requests. Let me compare them with CRUD.
▪ GET is used to retrieve information which is similar to Read
▪ POST is used to create new record which is similar to Create
▪ PUT is used to update record which is similar to Update
▪ DELETE is used to delete record which is similar to Delete

How to Create and Consume Simple REST API in PHP


JSON format is the most common output format of REST API, we will use the JSON format to
consume our simple REST API. We will develop an online transaction payment REST API for
our example. I will try to keep it as simple as possible so i will use GET request to retrieve
information.
1. Create REST API in PHP
2. Consume REST API in PHP

1. Create REST API in PHP


To create a REST API, follow these steps:

25
Web Programming (3160713) PROF. DEVANSHI DAVE
A. Create a Database and Table with Dummy Data
B. Create a Database Connection
C. Create a REST API File
A. Create a Database and Table with Dummy Data
To create database run the following query.

CREATE DATABASE allphptricks;

To create a table run the following query. Note: I have already attached the SQL file of this table
with dummy data, just download the complete zip file of this tutorial.

CREATE TABLE IF NOT EXISTS `transactions` (


`id` int(20) NOT NULL AUTO_INCREMENT,
`order_id` int(50) NOT NULL,
`amount` decimal(9,2) NOT NULL,
`response_code` int(10) NOT NULL,
`response_desc` varchar(50) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `order_id` (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;

B. Create a Database Connection


Just create a db.php file and paste the following database connection in it. Make sure that you
update these credentials with your database credentials.
// Enter your Host, username, password, database below.
$con = mysqli_connect("localhost","root","","allphptricks");
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " .mysqli_connect_error();
die();
}

C. Create a REST API File


Create a api.php file and paste the following script in it.
<?php
header("Content-Type:application/json");
if (isset($_GET['order_id']) && $_GET['order_id']!="") {
include('db.php');
$order_id = $_GET['order_id'];
$result = mysqli_query(
$con,
"SELECT * FROM `transactions` WHERE order_id=$order_id");
if(mysqli_num_rows($result)>0){
$row = mysqli_fetch_array($result);
$amount = $row['amount'];
$response_code = $row['response_code'];
$response_desc = $row['response_desc'];
response($order_id, $amount, $response_code,$response_desc);

26
Web Programming (3160713) PROF. DEVANSHI DAVE
mysqli_close($con);
}else{
response(NULL, NULL, 200,"No Record Found");
}
}else{
response(NULL, NULL, 400,"Invalid Request");
}

function response($order_id,$amount,$response_code,$response_desc){
$response['order_id'] = $order_id;
$response['amount'] = $amount;
$response['response_code'] = $response_code;
$response['response_desc'] = $response_desc;

$json_response = json_encode($response);
echo $json_response;
}
?>

The above script will accept the GET request and return output in the JSON format.
I have created all these files in folder name rest, now you can get the transaction information by
browsing the following URL.

http://localhost/rest/api.php?order_id=15478959

You will get the following output.

Above URL is not user friendly, therefore we will rewrite URL through the .htaccess file, copy
paste the following rule in .htaccess file.
RewriteEngine On # Turn on the rewriting engine

RewriteRule ^api/([0-9a-zA-Z_-]*)$ api.php?order_id=$1 [NC,L]

Now you can get the transaction information by browsing the following URL.
http://localhost/rest/api/15478959

You will get the following output.

2. Consume REST API in PHP


To consume a REST API, follow these steps:

27
Web Programming (3160713) PROF. DEVANSHI DAVE
1. Create an Index File with HTML Form
2. Fetch Records through CURL
1. Create an Index File with HTML Form
<form action="" method="POST">
<label>Enter Order ID:</label><br />
<input type="text" name="order_id" placeholder="Enter Order ID" required/>
<br /><br />
<button type="submit" name="submit">Submit</button>
</form>

2. Fetch Records through CURL


<?php
if (isset($_POST['order_id']) && $_POST['order_id']!="") {
$order_id = $_POST['order_id'];
$url = "http://localhost/rest/api/".$order_id;

$client = curl_init($url);
curl_setopt($client,CURLOPT_RETURNTRANSFER,true);
$response = curl_exec($client);

$result = json_decode($response);

echo "<table>";
echo "<tr><td>Order ID:</td><td>$result->order_id</td></tr>";
echo "<tr><td>Amount:</td><td>$result->amount</td></tr>";
echo "<tr><td>Response Code:</td><td>$result->response_code</td></tr>";
echo "<tr><td>Response Desc:</td><td>$result->response_desc</td></tr>";
echo "</table>";
}
?>

You can do anything with these output data, you can insert or update it into your own database if
you are using REST API of any other service provider. Usually in case of online transaction, the
service provider provides status of payment via API. You can check either payment is made
successfully or not. They also provide a complete guide of it.
Note: Make sure CURL is enabled on your web server or on your localhost when you are
testing demo.

28

You might also like