Back to Top

How to use WebService in PHP

HOW TO USE WEBSERVICE IN PHP

In this post, I am going to explain, how to call web service using PHP. Nowadays every website is using android or iOS application. To use web data to the application web services are used. We can simply say web services are the bridge to connect web data with the mobile application.

Earlier I have explained how to use Webservices in WordPress but not written about how to call using core PHP So, I thought it’s right the time to write one now.

Web Service means some data comes at PHP side as Request, We serve the request in PHP and did some manipulation with the database and send Response.

For Testing a Web service, We can use extensions provided in chrome which is known as Advanced Rest Client.You can install the addon and check your Webservices.Same addon available for Mozilla also.

Following Add-ons link for Mozilla

https://addons.mozilla.org/en-us/firefox/addon/restclient/

Following Extension link for Chrome

http://code.google.com/p/chrome-rest-client/

Download addon and install it in your browser.That’s it. You are ready to use web services.

Let’s start to check how to create, test and use web service with example.

First of all, Create one file and set configuration of the database and physical path and relative path setting in it.

Next, create mysql class file for insert,update,delete function which is unique functionality for insert,delete,update any table data.

Here, I have created login.php which will check user is a register or not.

Step 1 This is request data in json format

Step 2 At PHP side we get data as

Step 3 Then You can apply

Step 4 Apply data manipulation to check user is exist or not.

Step 5 Then You will get generated Response.

Here, I am going to explaining using login example.

Explanation

Here login.php file will check web data is set when data requested via POST. If get data, decode that data. Next check decoded data with process login function that data exists in the database or not.

If data found, return success status with message or failure if not found. You need to pass data after encoding it so use json_encode to encoding a data.

Isn’t very easy to use web services with PHP? If you know any other better method, please share.If you have any comments or suggestion about this post, I would really appreciate it.

Comments (2)

  1. Can you plz tell me how to run above web service code. Is it necessary to use Advanced RESTClient extension..?

    1. Yeah, You can use Advanced RESTClient extension.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

The Readers’ Poll – June 2013

Posted on 11 years ago

Bhumi

WordPress Template Hierarchy Tutorial

Posted on 9 years ago

Bhumi