久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='uWk0w'><style id='uWk0w'><dir id='uWk0w'><q id='uWk0w'></q></dir></style></legend>

      1. <i id='uWk0w'><tr id='uWk0w'><dt id='uWk0w'><q id='uWk0w'><span id='uWk0w'><b id='uWk0w'><form id='uWk0w'><ins id='uWk0w'></ins><ul id='uWk0w'></ul><sub id='uWk0w'></sub></form><legend id='uWk0w'></legend><bdo id='uWk0w'><pre id='uWk0w'><center id='uWk0w'></center></pre></bdo></b><th id='uWk0w'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='uWk0w'><tfoot id='uWk0w'></tfoot><dl id='uWk0w'><fieldset id='uWk0w'></fieldset></dl></div>
          <bdo id='uWk0w'></bdo><ul id='uWk0w'></ul>

        <small id='uWk0w'></small><noframes id='uWk0w'>

        <tfoot id='uWk0w'></tfoot>

      2. 清理和驗證表單 php

        Sanitizing and validating form php(清理和驗證表單 php)

        • <legend id='iRhCG'><style id='iRhCG'><dir id='iRhCG'><q id='iRhCG'></q></dir></style></legend>
            <bdo id='iRhCG'></bdo><ul id='iRhCG'></ul>
            <i id='iRhCG'><tr id='iRhCG'><dt id='iRhCG'><q id='iRhCG'><span id='iRhCG'><b id='iRhCG'><form id='iRhCG'><ins id='iRhCG'></ins><ul id='iRhCG'></ul><sub id='iRhCG'></sub></form><legend id='iRhCG'></legend><bdo id='iRhCG'><pre id='iRhCG'><center id='iRhCG'></center></pre></bdo></b><th id='iRhCG'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='iRhCG'><tfoot id='iRhCG'></tfoot><dl id='iRhCG'><fieldset id='iRhCG'></fieldset></dl></div>

              <tbody id='iRhCG'></tbody>

            <small id='iRhCG'></small><noframes id='iRhCG'>

                  <tfoot id='iRhCG'></tfoot>
                  本文介紹了清理和驗證表單 php的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  完全陷入深層次 - PHP 的新手并做了一個簡單的表單提交(創建帳戶頁面)以發送到 mySQL 數據庫,因此對于問題的noobness 表示歉意.

                  Completely thrown in the deep end - new to PHP and doing a simple form submission (create account page) to send to a mySQL database so apologies for the noobness of question.

                  我不確定如何在發送數據之前正確驗證和清理數據.但是我在插入數據庫時??使用了 PDO 和占位符,所以我想我已經涵蓋了這一方面.

                  I'm not sure how to properly validate and sanitize the data before sending it. But i am using a PDO and placeholders when inserting into the database so I think i have that side covered.

                  <form action="createaccount.php" name="form" method="post">
                      <input type="text" name="createUserName" id="createUserName" placeholder="User Name"><br>
                      <input type="password" name="passWord" id="passWord" placeholder="Password (Min 6 Characters)"><br>
                      <input type="password" name="confirmPW" id="confirmPW" placeholder="Confirm Password"><br>
                  
                      <input type="text" name="fName" id="fName" placeholder="First Name"><br>
                      <input type="text" name="sName" id="sName" placeholder="Surname"><br><br>
                  
                      <input type="email" name="userEmail" id="userEmail" placeholder="Email Address"><br>
                      <input type="submit" value="Create Account">
                  </form>
                  

                  這被發送到一個名為 createaccount.php 的單獨 php 文件,該文件運行用戶名檢查,如果成功則運行一個函數,將字段發送到我的 dbHandler 類中的插入函數中.

                  This is sent to a seperate php file called createaccount.php which runs a username check and if success runs a function that sends the fields into an insert function in my dbHandler class.

                  <?php 
                  session_start();
                  include('connect.php'); 
                  
                    $username = $_POST['createUserName'];
                    $password = $_POST['passWord'];
                    $password_confirm = $_POST['confirmPW'];
                    $firstname = $_POST['fName'];
                    $surname = $_POST['sName'];
                    $email = $_POST['userEmail'];
                  
                    if ($dbh->checkUserName($username)) {
                      $_SESSION['message'] = "Username is taken, please try again";
                      header('Location: createAccount.php');
                    exit();
                    } else {
                      $dbh->createAccount($username, $password, $password_confirm, $firstname, $surname, $email);
                      header('Location: login.php');
                      exit();
                    };
                  
                   ?>
                  

                  所以我的問題是.我應該使用

                  So my questions are. Should i be using

                  <?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>
                  

                  在我的表單中操作?如果是這樣.我需要在 createaccount.php 上運行該函數,是的,因為我無法將其發送到另一個 php 文件?

                  In my form action? If so. I will need to run the function on createaccount.php here yes as I cant send it to another php file?

                  我應該使用 filter_var 嗎?和/或我應該在我發送到表單的變量中使用修剪、斜線或任何東西嗎?我該怎么做呢?我的理解是

                  Should I be using filter_var? And/Or Should I be using trim, stripslashes or anything in my variables im sending into the form? How do I do this? My understanding is

                  $name = test_input($_POST['createUserName']);
                  $password = test_input($_POST['passWord']); .. etc
                  
                  function test_input($data) {
                          $data = trim($data);
                          $data = stripslashes($data);
                          $data = htmlspecialchars($data);
                  return $data;
                  }
                  

                  另外,這是我的插入函數.這是否安全/編寫正確?

                  Also, here is my insert function. Is this secure/written correctly?

                  <?php 
                  function createAccount($userName, $pw, $confirmPW, $fName, $sName, $email) {
                          $sql = "INSERT INTO `room_project`.`user` (`userName`, `pass`, `confirmPW`, `fName`, `sName`, `email`) VALUES (?, ?, ?, ?, ?, ?);";
                          $query = $this->connection->prepare($sql);
                          $query->execute(Array($userName, $pw, $confirmPW, $fName, $sName, $email));
                  
                      }
                  
                  ?>
                  

                  我非常感謝任何建議!再次請原諒這個初學者的性質:)

                  I thoroughly appreciate any advice! Again please excuse the beginner nature of this :)

                  推薦答案

                  你應該使用 PHP regex 來嚴格驗證您的輸入數據.

                  You should use PHP regex to strictly validate your input data.

                  假設您要驗證以下輸入字段,

                  Suppose you want to validate the following input fields,

                  • 用戶名
                  • 密碼
                  • 名字
                  • 姓氏
                  • 電子郵件

                  然后你會做這樣的事情,

                  then you would do something like this,

                  if(isset($_POST['submit']) && !empty($_POST['submit'])){
                  
                      // use a boolean variable to keep track of errors
                      $error = false;
                  
                      // Username validation
                      $username = trim($_POST['username']);
                      $username_pattern = "/^[a-zA-Z0-9]{3,15}$/"; // username should contain only letters and numbers, and length should be between 3 and 15 characters
                      if(preg_match($username_pattern, $username)){
                          // success
                      }else{
                          // error
                          $error = true;
                      }
                  
                      // Password validation
                      $password = $_POST['password'];
                      $confirm_password = $_POST['confirm_password'];
                      if(strlen($password) >= 6 && $password===$confirm_password){ // length of the password should be greater than or equal to 6
                         // success
                      }else{
                         // error
                         $error = true;
                      }
                  
                      // First name validation
                      $first_name = trim($_POST['first_name']);
                      $first_name_pattern = "/^[a-zA-Z]{2,15}$/";
                      if(preg_match($first_name_pattern, $first_name)){ // first name should contain only letters and length should be between 2 and 15 characters
                          // success
                      }else{
                          // error
                          $error = true;
                      }
                  
                  
                      // Last name validation
                      $last_name = trim($_POST['last_name']);
                      $last_name_pattern = "/^[a-zA-Z]{2,15}$/";
                      if(preg_match($last_name_pattern, $last_name)){ // last name should contain only letters and length should be between 2 and 15 characters
                          // success
                      }else{
                          // error
                          $error = true;
                      }
                  
                      // Email validation
                      $email = trim()
                      $email_pattern = "/^([a-z0-9._+-]{3,30})@([a-z0-9-]{2,30})((.([a-z]{2,20})){1,3})$/";
                      if(preg_match($email_pattern, $email)){ // validate email addresses
                          // success
                      }else{
                          // error
                          $error = true;
                      }
                  
                      if(!$error){
                          // all fields are validated. Now do your database operations.
                      }else{
                          // display error message
                      }
                  }
                  

                  并使用 PDO prepare 來防止您的數據庫受到任何類型的 SQL 注入.

                  And use PDO prepare to prevent your database from any kind of SQL Injection.

                  來自 PDO::prepare

                  為將使用不同參數值多次發出的語句調用 PDO::prepare() 和 PDOStatement::execute() 通過允許驅動程序協商客戶端和/或服務器端緩存來優化應用程序的性能查詢計劃和元信息,并且無需手動引用參數,有助于防止 SQL 注入攻擊.

                  Calling PDO::prepare() and PDOStatement::execute() for statements that will be issued multiple times with different parameter values optimizes the performance of your application by allowing the driver to negotiate client and/or server side caching of the query plan and meta information, and helps to prevent SQL injection attacks by eliminating the need to manually quote the parameters.

                  這篇關于清理和驗證表單 php的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                1. <tfoot id='TZNKR'></tfoot>
                    <bdo id='TZNKR'></bdo><ul id='TZNKR'></ul>

                        • <legend id='TZNKR'><style id='TZNKR'><dir id='TZNKR'><q id='TZNKR'></q></dir></style></legend>

                            <small id='TZNKR'></small><noframes id='TZNKR'>

                              <tbody id='TZNKR'></tbody>

                            <i id='TZNKR'><tr id='TZNKR'><dt id='TZNKR'><q id='TZNKR'><span id='TZNKR'><b id='TZNKR'><form id='TZNKR'><ins id='TZNKR'></ins><ul id='TZNKR'></ul><sub id='TZNKR'></sub></form><legend id='TZNKR'></legend><bdo id='TZNKR'><pre id='TZNKR'><center id='TZNKR'></center></pre></bdo></b><th id='TZNKR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='TZNKR'><tfoot id='TZNKR'></tfoot><dl id='TZNKR'><fieldset id='TZNKR'></fieldset></dl></div>
                          1. 主站蜘蛛池模板: 欧美一级三级在线观看 | 韩日在线 | 精品欧美二区 | 久久精品国产亚洲 | 成人免费看片又大又黄 | 九九综合九九 | 在线国产一区 | 日韩不卡三区 | 欧美综合视频在线 | 91在线观| 日中文字幕在线 | 国产一级一级 | 日韩在线播放一区 | 欧美在线一区二区三区 | 久久不卡| 超碰成人免费 | 国产精品一区二区久久 | 国产成人精品免费 | 欧美精品 在线观看 | 狠狠干2020 | 99视频入口| 九九亚洲| 国产精品一区二区无线 | 亚洲在线一区二区 | 国户精品久久久久久久久久久不卡 | 国产视频一区二区在线观看 | 九九亚洲 | 一区二区精品电影 | 亚洲高清免费视频 | 国外成人免费视频 | 成人亚洲精品久久久久软件 | 亚洲毛片在线观看 | 亚洲欧美一区二区三区视频 | 成人性视频免费网站 | 一本大道久久a久久精二百 欧洲一区二区三区 | 一区中文字幕 | 青青草华人在线视频 | 欧美一区二区视频 | 中国三级黄色录像 | 精品九九| 国产精品无码专区在线观看 |