[iOS/Android开发之WebService]How to write a webservices using php with json format
来源:互联网 发布:公司取名软件下载 编辑:程序博客网 时间:2024/05/16 01:58
How to write a webservices using php with json format
Hi friends, In this post i would like to explain about how to write a web services using php with the json format. Now a days mobile applications are more popular. Most of mobile applications are implementing for existing websites. To isplay information from database to mobile one mediator is require. So that mediator implementing using php and the output as JSON format to easy to retrieve.
Web service for login method. Code is continue with user class which i mentioned in my previous post object oriented programming in php
Login Method Code
function login($username,$password){ $query = "select * from users where username='".$username."' AND password='".$password."'"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); return $num_rows; }
In the web service page.
<?php /********************************************************************** * Author : Anil Kumar Panigrahi * E-mail : kumaranil21@gmail.com * Created on : 14th June 2011 * Version : 1.0 * Project : Wevservices * Page : Login Webservice * Company : Anil Labs (http://www.anil2u.info) * Modified on : * Modified by : *************************************************************************/// Includes the class which have the all functionsini_set('display_errors', '1');include_once("user.class.php");/* Created object for User class*/$web = new users();/* This file return the sucess or failure with provided details ( username, password ) */// USER NAME - user_name// PASSWORD - passwordif(isset($_REQUEST) && ($_REQUEST['user_name'] != "") && ($_REQUEST['password']!="") ){ $result = $web->login($_REQUEST['user_name'],$_REQUEST['password']); echo json_encode(array('results'=>$result));}/* Provided output in the json encoded format */// Call the database disconnection method$web->connection_close();?>
Call this method as
http://localhost/login.php?username=anil&password=123456
Output:
if correct {“result”:1} else {“result”:0}
- [iOS/Android开发之WebService]How to write a webservices using php with json format
- How To Write A Simple PHP/MySQL Web Service for an iOS App(1)
- How To Write A Simple PHP/MySQL Web Service for an iOS App(2)
- How To Write A Simple PHP/MySQL Web Service for an iOS App
- How To Write A Simple PHP/MySQL Web Service for an iOS App
- How to format a JavaScript date(jquery ,json ,日期)
- How to pad a file with “FF” using dd?
- How to post JSON to PHP with curl
- How to write a Makefile
- How to write a Makefile
- how to write a makefile
- How to Write a Summary?
- How to write a Makefile
- How to write a Makefile
- How to write a paper
- how to write a makefile
- how to write a plugin
- How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
- 递归算法总结
- reverse的时候release版本和debug版本的不同之处
- 推荐一下我们的Lotus Notes/Domino团队博客
- C#中设置console和form同时显示
- poj 2371 questiong and answer
- [iOS/Android开发之WebService]How to write a webservices using php with json format
- 集成第三方库到android程序方法
- MyEclipse6.0注册码生成类(Java)
- 获取本地IP
- 判断素数 Miller-Rabin 算法
- destoon二次开发模板和调用语法参考
- android webview
- apache mina 学习(九)-----IoBuffer
- 【iOS-cocos2d-X 游戏开发之五】游戏存储之Cocos2dX自带CCUserDefault类详解;