PHP API Data Interface Writing example

Source: Internet
Author: User
The following small series for everyone to bring a PHP API data interface writing examples. Small series think very good, now share PHP write API interface code to everyone, also for everyone to do a reference. Be interested in PHP writing API interface follow the small part to see it

The following is an example of an interface code:

<?php$output = Array (); $a = @$_get[' a ']? $_get[' A ']: '; $uid = @$_get[' uid ']?  $_get[' uid ']: 0;if (Empty ($a)) {$output = array (' Data ' =>null, ' info ' = ' Hang Dad! '); ' Code ' =>-201); Exit (Json_encode ($output));} Go to the interface if ($a = = ' get_users ') {//Check the user if ($uid = = 0) {$output = array (' Data ' =>null, ' info ' = ' The UID is null! ', ' Co  De ' =>-401); exit (Json_encode ($output)); }//Assume that $mysql is a database $mysql = Array (10001 = = Array (' UID ' =>10001, ' VIP ' =>5, ' nickname ' = = ' Shine X ', ' Emai L ' = ' 979137@qq.com ', ' QQ ' =>979137, ' Gold ' =>1500, ' powerplay ' + = Array (' 2XP ' =>12, ' Gem ' =>12, ' bingo ' =>5, ' Keys ' =>5, ' chest ' =>8 ', ' gems ' = = Array (' Red ' =>13, ' green ' =>3, ' Blue ' =>8, ' yellow ' =>17), ' CTime ' =>1376523234, ' lastlogin ' =>1377123144, ' level ' =>19, ' exp ' =>16758, ' 10002 ' (' uid ' = ') ' 10002, ' VIP ' =>50, ' nickname ' = ' Elva ', ' email ' = ' elva@ezhi.net ', ' QQ ' =>null, ' Gold ' =>14320, ' POWERPL Ay ' = = Array (' 2XP ' =&GT;1, ' Gem ' =>120, ' Bingo ' =>51, ' Keys ' =>5, ' chest ' =>8 ', ' gems ' = = Array (' Red ' =>13, ' green ' =>3, ' Blue ' =>8, ' yellow ' =>17, ' CTime ' =>1376523234, ' lastlogin ' =>1377123144, ' level ' =>112, ' exp ' =  167588,), 10003 = = Array (' uid ' = 10003, ' vip ' = 5, ' nickname ' = ' Lily ', ' email ' = ' Lily@ezhi.net ', ' QQ ' = NULL, ' gold ' = 1541, ' powerplay ' = = Array (' 2XP ' =>2, ' Gem ' =>112, ' Bingo ' =>4, ' Keys ' =>7, '  Chest ' =>8), ' gems ' = = Array (' Red ' =>13, ' green ' =>3, ' Blue ' =>9, ' yellow ' =>7), ' ctime ' = 1376523234,  ' Lastlogin ' = 1377123144, ' level ', ' + ', ' exp ' = 1758, ');  $UIDARR = Array (10001,10002,10003);  if (In_array ($uid, $UIDARR, True)) {$output = array (' data ' = NULL, ' info ' = ' The user does not exist! ', ' code ' =  -402); exit (Json_encode ($output));  }//Query database $userInfo = $mysql [$uid]; Output Data $output = Array (' userInfo ' + = $userInfo, ' islogin ' = true,//whether the first login ' unread' = = 4,//Unread message number ' untask ' = 3,//unfinished task], ' info ' = ' Here's the message which, commonly used in popup window ',// The message indicates that the client often uses this as a popup information.  ' Code ' = 200,//success and failure codes, usually positive or negative; Exit (Json_encode ($output));}  ElseIf ($a = = ' Get_games_result ') {//... die (' You are tuning Get_games_result interface! ');} elseif ($a = = ' Upload_avatars ') {/... Die (' You are tuning Upload_avatars interface! ');}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.