婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > PHP實現的用戶注冊表單驗證功能簡單示例

PHP實現的用戶注冊表單驗證功能簡單示例

熱門標簽:銀川ai電話機器人 電梯外呼線路板維修視頻 芒果電銷機器人 上海公司外呼系統線路 浙江外呼電話系統軟件 臨沂智能電銷機器人軟件 十堰ai電話機器人效果怎么樣 地圖標注風向標 安陽自動外呼系統價格是多少

本文實例講述了PHP實現的用戶注冊表單驗證功能。分享給大家供大家參考,具體如下:

注冊界面

register.html

  h1>用戶注冊/h1>
  form method="post" action="register_verify.php">
    input type="text" placeholder="用戶名" name="username">br>br>
    input type="password" placeholder="密碼" name="password">br>br>
    input type="password" placeholder="重復密碼" name="password2">br>br>
    label>性別:
      input type="radio" name="sex" value="男" checked="checked">男
      input type="radio" name="sex" value="女">女/label>br>br>
    input type="email" placeholder="郵箱" name="email">br>br>
    button class="btn" type="submit">注冊/button>
  /form>

register_verify.php

?php
require "mysql.php";      //導入mysql.php訪問數據庫
$username=$_POST['username'];
$password=$_POST['password'];
$password2=$_POST['password2'];
$sex=$_POST['sex'];
$email=$_POST['email'];
if(checkEmpty($username,$password,$password2,$sex,$email)){
  if(checkpwd($password,$password2)){
    if(checkEmail($email)){
      if(insert($username,$password,$sex,$email))
        echo"注冊成功";
    }
  }
}
//方法:判斷是否為空
function checkEmpty($username,$password,$password2,$sex,$email){
  if($username==null||$password==null||$password2==null){
    echo 'html>head>Script Language="JavaScript">alert("用戶名或密碼為空");/Script>/head>/html>'       . "meta http-equiv=\"refresh\" content=\"0;url=register.html\">";
  }
  else{
    if($sex==null){
      echo 'html>head>Script Language="JavaScript">alert("性別為空");/Script>/head>/html>' .          "meta http-equiv=\"refresh\" content=\"0;url=register.html\">";
    }
    elseif($email==null){
      echo 'html>head>Script Language="JavaScript">alert("郵箱為空");/Script>/head>/html>' .          "meta http-equiv=\"refresh\" content=\"0;url=register.html\">";
    }
    else{
      return true;
    }
  }
}
//方法:檢查兩次密碼是否相同
function checkpwd($password,$password2){
  if($password==$password2)
    return true;
  else
    echo 'html>head>Script Language="JavaScript">alert("兩次密碼不一致");/Script>/head>/html>' .        "meta http-equiv=\"refresh\" content=\"0;url=register.html\">";
}
//方法:郵箱格式驗證
function checkEmail($email){
  $preg = '/^(\w{1,25})@(\w{1,16})(\.(\w{1,4})){1,3}$/';
  if(preg_match($preg, $email)){
    return true;
  }else{
    echo 'html>head>Script Language="JavaScript">alert("郵箱格式有誤");/Script>/head>/html>' .        "meta http-equiv=\"refresh\" content=\"0;url=register.html\">";
  }
}
//方法:將數據插入數據庫中
function insert($username,$password,$sex,$email){
  $conn=new Mysql();
  $sql="insert into user VALUE (null,'$username','$password','$sex','$email')";
  $result=$conn->sql($sql);
  if($result){
    return true;
  }
  else{
    echo 'html>head>Script Language="JavaScript">alert("寫入數據庫失敗");/Script>/head>/html>' .        "meta http-equiv=\"refresh\" content=\"0;url=register.html\">";
  }
  $conn->close();
}

驗證碼和數據庫的實現方法前面寫過,這里不再贅述。

可參考前面兩篇文章:

PHP封裝mysqli基于面向對象的mysql數據庫操作類

PHP通過GD庫實現驗證碼功能

PS:這里再為大家提供2款非常方便的正則表達式工具供大家參考使用:

JavaScript正則表達式在線測試工具:
http://tools.jb51.net/regex/javascript

正則表達式在線生成工具:
http://tools.jb51.net/regex/create_reg

更多關于PHP相關內容感興趣的讀者可查看本站專題:《php程序設計安全教程》、《php安全過濾技巧總結》、《PHP基本語法入門教程》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》

希望本文所述對大家PHP程序設計有所幫助。

您可能感興趣的文章:
  • PHP登錄驗證功能示例【用戶名、密碼、驗證碼、數據庫、已登陸驗證、自動登錄和注銷登錄等】
  • ubutu 16.04環境下,PHP與mysql數據庫,網頁登錄驗證實例講解
  • php使用sql server驗證連接數據庫的方法
  • php驗證用戶名是否以字母開頭與驗證密碼實例
  • php用戶注冊頁面利用js進行表單驗證具體實例
  • PHP+Ajax驗證碼驗證用戶登錄
  • php面向對象的用戶登錄身份驗證
  • PHP用戶驗證和標簽推薦的簡單使用
  • 通過緩存數據庫結果提高PHP性能的原理介紹
  • PHP利用緩存處理用戶注冊時的郵箱驗證,成功后用戶數據存入數據庫操作示例

標簽:武威 遵義 荊門 遂寧 吐魯番 常州 寧夏 徐州

巨人網絡通訊聲明:本文標題《PHP實現的用戶注冊表單驗證功能簡單示例》,本文關鍵詞  PHP,實現,的,用戶注冊,表單,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《PHP實現的用戶注冊表單驗證功能簡單示例》相關的同類信息!
  • 本頁收集關于PHP實現的用戶注冊表單驗證功能簡單示例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 鸡东县| 始兴县| 千阳县| 都江堰市| 许昌市| 右玉县| 荔波县| 沧州市| 波密县| 昭觉县| 台北县| 庆城县| 阿坝县| 英超| 南平市| 文化| 高清| 监利县| 宣恩县| 汽车| 大安市| 南投县| 荣成市| 拉萨市| 铜陵市| 福州市| 黄平县| 揭阳市| 中山市| 达拉特旗| 泌阳县| 三门县| 抚顺县| 嘉定区| 利辛县| 湛江市| 霍州市| 平乡县| 类乌齐县| 罗甸县| 淮滨县|