You are here
Home > Php > How to Create Web Service in PHP

How to Create Web Service in PHP

Hello Friends, Today I am going to tell you about how to create web service in PHP. A web service is a software or program which makes itself available over Internet to give response according to inputs provided to web service. In a Web service, HTTP protocol is used for communication and response is generated to client in XML or JSON format. Web Services can be utilized by web application, mobile applications or desktop applications. Web Services can be created using Java, .Net, PHP or any other languages but I am going to use PHP and response will be generated in JSON format. I am going to create a web service for user registration and login.

Folder Structure

website_root_folder/api/config.php
website_root_folder/api/user.php

Note: website root folder can be public_html or a subfolder or depend on your web server and how to setup your website

config.php

user.php

Service url will be SITE_URL/api/user.php

How to Access Web Service

Registration Web Service

SITE_URL/api/user.php?key=ABCD&action=register&name=Test&mobile=9999999999&[email protected]&password=test
i.e. http://example.com/api/user.php?key=ABCD&action=register&name=Test&mobile=9999999999&[email protected]&password=test

Login Web Service

SITE_URL/api/user.php?key=ABCD&action=login&emailormobile=9999999999&password=test
i.e. http://example.com/api/user.php?key=ABCD&action=login&emailormobile=9999999999&password=test

Note: Here I am using GET method you can also use POST method

 

Please share if you like and you can ask in comment section if you have any query

Rajesh Kumar Sahanee
I am a passionate Java Developer and I like Computer Programming. I love to do some interesting experiments and listening music in my free time.
https://www.zatackcoder.com

Comments

zatackcoder
Top

  Â