PHP development API interface registration, login, query User Information Server & lt ;? Phprequireconn. php; header (Content-Type: texthtml; charsetutf-8); $ action $ _ GET [action]; switch ($ action) {registered member case & quot; adduseri PHP development API interface registration, login, query user information
Server
0) {exit (json_encode (1); // return 1 indicates registration failed} else {$ addsql = "insert into 'member' (username, password, email) values ('$ username',' $ password', '$ email') "; mysql_query ($ addsql); exit (json_encode (0 )); // return 0 indicating successful registration} break; // query User information case "selectuserinfo"; $ username = lib_replace_end_tag ($ _ GET ['username']); $ SQL = "select id, username, nickname, mobile from 'member' where username = '$ username'"; $ query = mysql_qu Ery ($ SQL, $ conn); $ row = mysql_fetch_array ($ query); foreach ($ row as $ key => $ v) {$ res [$ key] = urlencode ($ v);} exit (json_encode ($ res); break; // member logon case "userlogin "; $ username = lib_replace_end_tag ($ _ GET ['username']); $ password2 = lib_replace_end_tag (trim ($ _ GET ['userpassword']); $ password = md5 ("$ password2 ". ALL_PS); $ sqluser = "select id, username, password from 'member' where username = '". $ u Sername. "'and password = '". $ password. "'"; $ queryuser = mysql_query ($ sqluser); $ rowuser = mysql_fetch_array ($ queryuser); if ($ rowuser & is_array ($ rowuser )&&! Empty ($ rowuser) {if ($ rowuser ['username'] = $ username & $ rowuser ['password'] = $ password) {if ($ rowuser ['password'] = $ password) {$ res = urlencode ("logon successful"); exit (json_encode ($ res ));} else {$ res = urlencode ("incorrect password"); exit (json_encode ($ res) ;}} else {$ res = urlencode ("the user name does not exist "); exit (json_encode ($ res) ;}} else {$ res = urlencode ("incorrect user name and password"); exit (json_encode ($ res);}/** 0: indicates that the logon is successful. 1: indicates that the password is incorrect. Error: 2: The user name does not exist; 3: The user name and password are incorrect */break; default: exit (json_encode (error);}?>
Client example: