[php]表單和驗證

來源:互聯網
上載者:User

標籤:blog   http   io   ar   os   使用   sp   on   檔案   

<?php/*  表單的作用: 通過表單 發布和收集  資訊.  對html表單進行編碼  只是有效接受使用者輸入的必要操作的(一部分), 必須由[伺服器端]組件來處理  一 標題函數(header()) 標題(header)是 伺服器 從http協議 傳html資料到瀏覽器 在[標題]和[html檔案]之間 需空一行分隔.  header() 函數用來發送一個原始 HTTP 標題。 void header ( string string [, bool replace [, int http_response_code]] )  標題 可以 有兩種形式: 1. 重導向  指定的url header(‘Location:http://www.baidu.com‘); 2. 設定  頁面字元編碼   header(‘Content-Type: text/html; charset=utf-8‘);      [注意]除非啟用了{輸出緩衝}, 否則 這些命令必須放在  返回任何輸出的語句之前執行.(就是放在檔案的開頭)啟用輸出緩衝: ob_start();      使用$_POST和$_GET 接受資料:1. $_GET[‘username‘]發送的表單   method必須是get;2. $_POST[‘username‘]發送的表單  method必須是post;3. 用 isset() 驗證 $_GET[‘username‘]超級全域變數 是否定義;4. 使用 htmlspecialchars() 過濾 html特殊字元.   對{資料有效性}進行 驗證:1. trim() 去除資料的前後 空格;2. strlen() 判斷資料的長度;3. is_nuimeric() 判斷資料是否純數字;4. 用{Regex} 驗證郵箱是否合法.    *//*if(!isset($_POST[‘send‘]) || $_POST[‘send‘]!=‘提交‘){header(‘Location:demo1.php‘);exit;}else{echo "<h1>". $_POST[‘name‘]."</h1> <br><b>".$_POST[‘said‘]."</b>";}*//*  例如一個產生的 PDF 檔案,可以通過發送 Content-Disposition 標題提供推薦的檔案名稱來強制瀏覽器彈出一個儲存檔案對話方塊。 <?php// 這樣將會直接輸出一個 PDF 檔案header(‘Content-type: application/pdf‘);// 這樣做就會提示下載 PDF 檔案 downloaded.pdfheader(‘Content-Disposition: attachment; filename="downloaded.pdf"‘);// 這是 original.pdf 的源檔案readfile(‘original.pdf‘);?>   *  *//*   表單元素描述 ----------------------------- text input文字框 password input密碼框 hidden input隱藏框 select下拉式清單 checkbox複選框 radio單選 textarea地區框 file上傳 submit提交按鈕 reset重設       *  *//* if (strlen($username)<2 ||strlen($username)>10) { echo "<script>alert(‘使用者名稱不能小於兩位或者大於10‘);history.back();</script>"; exit; } *//* if (preg_match( ‘/([\w\.]{2,255})@([\w\-]{1,255}).([a-z]{2,4})/‘ , $_POST [ ‘email‘ ])) {echo ‘ 電子郵件合法 ‘ ;} else {echo ‘ 電子郵件不合法 ‘ ;}  *  */?>

  

[php]表單和驗證

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.