富贵资源网 Design By www.hznty.com
本文实例讲述了PHP实现的注册,登录及查询用户资料功能API接口。分享给大家供大家参考,具体如下:
服务端
<"adduserinfo"; $username = lib_replace_end_tag(trim($_GET['username'])); $password2 = lib_replace_end_tag(trim($_GET['userpassword'])); $password = md5("$password2" . ALL_PS); $email = lib_replace_end_tag(trim($_GET['email'])); if ($username == '' || $password2 == '' || $password == '') { $res = urlencode("参数有误"); exit(json_encode($res)); //有空信息 } $sql = "select username from `member` where username='$username'"; $query = mysql_query($sql, $conn); $count = mysql_num_rows($query); if ($count > 0) { exit(json_encode(1)); //返回1表示注册失败 } else { $addsql = "insert into `member` (username,password,email) values ('$username','$password','$email')"; mysql_query($addsql); exit(json_encode(0)); //返回0表示注册成功 } break; //查询用户信息 case"selectuserinfo"; $username = lib_replace_end_tag($_GET['username']); $sql = "select id,username,nickname,mobile from `member` where username='$username'"; $query = mysql_query($sql, $conn); $row = mysql_fetch_array($query); foreach ($row as $key => $v) { $res[$key] = urlencode($v); } exit(json_encode($res)); break; //会员登录 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='" . $username . "' 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("登录成功"); exit(json_encode($res)); } else { $res = urlencode("密码错误"); exit(json_encode($res)); } } else { $res = urlencode("用户名不存在"); exit(json_encode($res)); } } else { $res = urlencode("用户名密码错误"); exit(json_encode($res)); } /* * 0:表示登录成功,1:表示密码错误,2:用户名不存在,3:用户名密码错误 */ break; default: exit(json_encode(error)); } "font-size: medium">客户端例子:<"curl_init error for url %s.", $url)); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 600); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); if (is_array($parms)) { curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data;')); } $postResult = @curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($postResult === false || $http_code != 200 || curl_errno($ch)) { $error = curl_error($ch); curl_close($ch); throw new Exception("HTTP POST FAILED:$error"); } else { // $postResult=str_replace("\xEF\xBB\xBF", '', $postResult); switch (curl_getinfo($ch, CURLINFO_CONTENT_TYPE)) { case 'application/json': $postResult = json_decode($postResult); break; } curl_close($ch); return $postResult; } } $postUrl = "http://pujia.test.com/api/server.php"; $p=$_GET['p']; if ($p =="selectuserinfo") { $username = $_GET['username']; $parms = "" . $username . ""; } elseif ($p =="adduserinfo") { $username = $_GET['username']; $userpassword = $_GET['userpassword']; $parms = "" . $username . "&userpassword=" . $userpassword . ""; } elseif ($p =="userlogin") { $username = $_GET['username']; $userpassword = $_GET['userpassword']; $parms = "" . $username . "&userpassword=" . $userpassword . ""; } $res = httpPost($postUrl, $parms); //$parms $res = json_decode($res); print_r(urldecode(json_encode($res))); "_blank" href="https://www.jb51.net/article/39392.htm">浅析php过滤html字符串,防止SQL注入的方法更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP+MySQL会员系统开发专题》、《php+mysql数据库操作入门教程》、《php+mysqli数据库程序设计技巧总结》、《php面向对象程序设计入门教程》、《PHP网络编程技巧总结》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?