最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP實(shí)現(xiàn)的注冊(cè),登錄及查詢用戶資料功能API接口示例

 更新時(shí)間:2017年06月06日 08:57:30   作者:程序加載中  
這篇文章主要介紹了PHP實(shí)現(xiàn)的注冊(cè),登錄及查詢用戶資料功能API接口,結(jié)合具體實(shí)例形式分析了php服務(wù)器端用戶注冊(cè)、登陸、查詢及curl登陸查詢功能實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了PHP實(shí)現(xiàn)的注冊(cè),登錄及查詢用戶資料功能API接口。分享給大家供大家參考,具體如下:

服務(wù)端

<?php
require 'conn.php';
header('Content-Type:text/html;charset=utf-8');
$action = $_GET['action'];
switch ($action) {
  //注冊(cè)會(huì)員
  case"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("參數(shù)有誤");
      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表示注冊(cè)失敗
    } else {
      $addsql = "insert into `member` (username,password,email) values ('$username','$password','$email')";
      mysql_query($addsql);
      exit(json_encode(0)); //返回0表示注冊(cè)成功
    }
    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;
  //會(huì)員登錄
  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("密碼錯(cuò)誤");
          exit(json_encode($res));
        }
      } else {
        $res = urlencode("用戶名不存在");
        exit(json_encode($res));
      }
    } else {
      $res = urlencode("用戶名密碼錯(cuò)誤");
      exit(json_encode($res));
    }
    /*
     * 0:表示登錄成功,1:表示密碼錯(cuò)誤,2:用戶名不存在,3:用戶名密碼錯(cuò)誤
     */
    break;
  default:
    exit(json_encode(error));
}
?>

客戶端例子:

<?php
header('Content-Type:text/html;charset=utf-8'); //避免輸出亂碼
function httpPost($url, $parms) {
  $url = $url . $parms;
  if (($ch = curl_init($url)) == false) {
    throw new Exception(sprintf("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 = "?action=selectuserinfo&username=" . $username . "";
} elseif ($p =="adduserinfo") {
  $username = $_GET['username'];
  $userpassword = $_GET['userpassword'];
  $parms = "?action=adduserinfo&username=" . $username . "&userpassword=" . $userpassword . "";
} elseif ($p =="userlogin") {
  $username = $_GET['username'];
  $userpassword = $_GET['userpassword'];
  $parms = "?action=userlogin&username=" . $username . "&userpassword=" . $userpassword . "";
}
$res = httpPost($postUrl, $parms); //$parms
$res = json_decode($res);
print_r(urldecode(json_encode($res)));
?>

注:代碼中的lib_replace_end_tag函數(shù)為自定義字符串過(guò)濾函數(shù),具體可參考:淺析php過(guò)濾html字符串,防止SQL注入的方法

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP+MySQL會(huì)員系統(tǒng)開發(fā)專題》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》、《php+mysqli數(shù)據(jù)庫(kù)程序設(shè)計(jì)技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • 一個(gè)PHP緩存類代碼(附詳細(xì)說(shuō)明)

    一個(gè)PHP緩存類代碼(附詳細(xì)說(shuō)明)

    一個(gè)PHP緩存類代碼,后面都有詳細(xì)的說(shuō)明,學(xué)習(xí)php的朋友可以參考下。
    2011-06-06
  • php實(shí)現(xiàn)的簡(jiǎn)單中文驗(yàn)證碼功能示例

    php實(shí)現(xiàn)的簡(jiǎn)單中文驗(yàn)證碼功能示例

    這篇文章主要介紹了php實(shí)現(xiàn)的簡(jiǎn)單中文驗(yàn)證碼功能,結(jié)合實(shí)例形式分析了php中文驗(yàn)證碼功能的實(shí)現(xiàn)步驟與操作方法,包括圖形創(chuàng)建、編碼操作、session操作等相關(guān)技巧,需要的朋友可以參考下
    2017-01-01
  • PHP高級(jí)對(duì)象構(gòu)建 多個(gè)構(gòu)造函數(shù)的使用

    PHP高級(jí)對(duì)象構(gòu)建 多個(gè)構(gòu)造函數(shù)的使用

    構(gòu)建對(duì)象是PHP面向?qū)ο缶幊淘O(shè)計(jì)中的一個(gè)重要主題。在最簡(jiǎn)單的情況下,普通構(gòu)造函數(shù)就夠用了,但如果要開展更為復(fù)雜的設(shè)計(jì),那么構(gòu)造函數(shù)可能會(huì)變的難以管理
    2012-02-02
  • PHP商品秒殺問(wèn)題解決方案實(shí)例詳解【mysql與redis】

    PHP商品秒殺問(wèn)題解決方案實(shí)例詳解【mysql與redis】

    這篇文章主要介紹了PHP商品秒殺問(wèn)題解決方案,結(jié)合實(shí)例形式詳細(xì)分析了php結(jié)合mysql與redis實(shí)現(xiàn)商品秒殺功能的相關(guān)操作技巧及注意事項(xiàng),需要的朋友可以參考下
    2019-07-07
  • php使用環(huán)形鏈表解決約瑟夫問(wèn)題完整示例

    php使用環(huán)形鏈表解決約瑟夫問(wèn)題完整示例

    這篇文章主要介紹了php使用環(huán)形鏈表解決約瑟夫問(wèn)題,簡(jiǎn)單描述了約瑟夫問(wèn)題并結(jié)合實(shí)例形式分析了php基于環(huán)形鏈表解決約瑟夫問(wèn)題的相關(guān)操作技巧,注釋中包含較為詳盡的說(shuō)明便于理解,需要的朋友可以參考下
    2018-08-08
  • php實(shí)現(xiàn)統(tǒng)計(jì)網(wǎng)站在線人數(shù)的方法

    php實(shí)現(xiàn)統(tǒng)計(jì)網(wǎng)站在線人數(shù)的方法

    這篇文章主要介紹了php實(shí)現(xiàn)統(tǒng)計(jì)網(wǎng)站在線人數(shù)的方法,通過(guò)獲取服務(wù)器端網(wǎng)絡(luò)參數(shù)及文本文件讀寫實(shí)現(xiàn)統(tǒng)計(jì)在線人數(shù)的功能,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下
    2015-05-05
  • PHP 多維數(shù)組排序(usort,uasort)

    PHP 多維數(shù)組排序(usort,uasort)

    當(dāng)我們想對(duì)多維數(shù)組進(jìn)行排序時(shí),多維數(shù)組的每個(gè)元素又是一數(shù)組類型,而兩個(gè)數(shù)組如何比較大小?這是需要用戶自定義的(是按每個(gè)數(shù)組的第一元素比較還是…)。
    2010-06-06
  • php去除字符串中空字符的常用方法小結(jié)

    php去除字符串中空字符的常用方法小結(jié)

    這篇文章主要介紹了php去除字符串中空字符的常用方法,實(shí)例分析了php中的trim()、ltrim()、rtrim()及chop()等函數(shù)的使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-03-03
  • php計(jì)算年齡精準(zhǔn)到年月日

    php計(jì)算年齡精準(zhǔn)到年月日

    這篇文章主要介紹了php計(jì)算年齡精準(zhǔn)到年月日的方法,涉及php操作日期與字符串的相關(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下
    2015-11-11
  • PHP針對(duì)中英文混合字符串長(zhǎng)度判斷及截取方法示例

    PHP針對(duì)中英文混合字符串長(zhǎng)度判斷及截取方法示例

    這篇文章主要介紹了PHP針對(duì)中英文混合字符串長(zhǎng)度判斷及截取方法,結(jié)合實(shí)例形式分析了php中英文字符串的遍歷、轉(zhuǎn)換、截取、計(jì)算等相關(guān)操作技巧,需要的朋友可以參考下
    2017-03-03

最新評(píng)論

洛隆县| 龙海市| 逊克县| 兴城市| 宜春市| 怀柔区| 张北县| 榆树市| 玉溪市| 宜州市| 东乡族自治县| 龙胜| 东乌珠穆沁旗| 乌海市| 清苑县| 金阳县| 阿拉善右旗| 出国| 古丈县| 同心县| 乌兰察布市| 凉山| 龙南县| 通江县| 交口县| 阿勒泰市| 仙游县| 汨罗市| 汉寿县| 石城县| 连江县| 和政县| 阿克苏市| 东乌| 肥城市| 庐江县| 正镶白旗| 庆城县| 普宁市| 万安县| 栾川县|