为了账号安全,请及时绑定邮箱和手机立即绑定

JSON和Ajax登录功能

JSON和Ajax登录功能

JimReder 2019-09-10 17:23:23
请问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);?> 
查看完整描述

3 回答

?
有课学课程返现平台

TA贡献11条经验 获得超12个赞

{"username":"有课学"}

类似上面这种 JSON 格式的字符串即可

查看完整回答
1 反对 回复 2019-09-25
  • 3 回答
  • 0 关注
  • 822 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信