PHP API Data Interface Writing example (recommended) _php instance

Source: Internet
Author: User

The following is an interface code instance:

<?php $output = Array (); $a = @$_get[' a ']?
$_get[' A ']: '; $uid = @$_get[' uid ']?
$_get[' uid ': 0;
  if (empty ($a)) {$output = array (' Data ' =>null, ' info ' => ' pit Dad! ', ' Code ' =>-201);
Exit (Json_encode ($output)); //GO interface if ($a = = ' get_users ') {//Check user if ($uid = = 0) {$output = array (' Data ' =>null, ' info ' => ' The UID is null!
', ' Code ' =>-401);
  Exit (Json_encode ($output));
  //Suppose $mysql is the database $mysql = Array (10001 => array (' UID ' =>10001, ' VIP ' =>5, ' nickname ' => ' Shine ' X '), ' Email ' => ' 979137@qq.com ', ' QQ ' =>979137, ' Gold ' =>1500, ' Powerplay ' => array (' 2XP ' =>12, ' Gem ' =>12, ' B Ingo ' =>5, ' Keys ' =>5, ' chest ' =>8, ' gems ' => Array (' Red ' =>13, ' green ' =>3, ' Blue ' =>8, ' yellow ' =>
  , ' CTime ' =>1376523234, ' lastlogin ' =>1377123144, ' level ' =>19, ' exp ' =>16758,), 10002 => Array ( ' UID ' =>10002, ' VIP ' =>50, ' nickname ' => ' Elva ', ' email ' => ' elva@ezhi.net ', ' QQ ' =>null, ' Gold ' =>14320, ' Powerplay ' => array (' 2XP ' =>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 ' =&G T;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 ' =&GT ;
-402);
  Exit (Json_encode ($output));

  //Query Database $userInfo = $mysql [$uid]; Output Data $output = Array (' Data ' => arrAy (' userInfo ' => $userInfo, ' islogin ' => true,//whether the first landing ' unread ' => 4,//unread message number ' Untask ' => 3,//the unfinished Task)
, ' info ' => ' Here's the message which, commonly used in popup window ',//Messages prompt, the client often uses this as the window information.
  ' Code ' => 200,//success and failure codes, usually positive or negative numbers;
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! '); }

The above is a small series for everyone to bring PHP API data Interface Writing example (recommended) All the content, I hope to help you, a lot of support cloud Habitat Community ~

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.