请问user.json应该写什么?<?phpheader('Content-Type:application/json');$isUsername = array_key_exists('username', $_REQUEST);$username = $isUsername ? $_REQUEST['username'] : '';if(!$username){ $msg = printMsg('参数有误',2); echo json_encode($msg,true); exit();}function printMsg($msg,$code){ return array( 'msg' => $msg, 'code' => $code );}$fileStr = __DIR__.'/user.json';$fileStream = fopen($fileStr,'r');$fileContent = fread($fileStream, filesize($fileStr));$fileContent_array = $fileContent ? json_decode($fileContent,true) : array();fclose($fileStream);// 判断用户名是否有重复的$isRepeat = false;foreach ($fileContent_array as $key => $val) { # code... if($val['username'] === $username){ $isRepeat = true; break; }}if($isRepeat){ $msg = printMsg('用户名重复',0); echo json_encode($msg,true); exit();}$msg = printMsg('用户名可用',1);echo json_encode($msg,true);?>
添加回答
举报
0/150
提交
取消