大姐求教PHP怎么进行API开发,如何写API,各种晕啊

WBOY
Release: 2016-06-13 12:26:43
Original
728 people have browsed it

各位大哥大姐求教PHP如何进行API开发,怎么写API,各种晕啊?
  最近要求我写个接口,实现调用接口即可实现把数据上传到数据库,从未写过接口,怎么写?该从何入手?毫无头绪! 求简单代码示例 
------解决思路----------------------
所谓接口就是连接客户端和服务端的程序
简单的说,如果你把你的网站中的数据库和业务逻辑去掉后的代码就是接口了

------解决思路----------------------
比较简单接口就是可以接受POST/GET的参数,然后以json方式输出返回。
例如,一个登入的接口。

<br />$username = isset($_GET['username'])? $_GET['username'] : '';<br />$password = isset($_GET['password'])? $_GET['password'] : '';<br /><br />$ret = array();<br />if($username=='fdipzone' && $password=='123456'){<br />    $ret['success'] = true;<br />}else{<br />    $ret['success'] = false;<br />}<br /><br />header('content-type:application/json');<br />echo json_encode($ret);<br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!