<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 輸入類 輸入類有兩個用途: 1. 為了安全性,對輸入數據進行預處理 2. 提供了一些輔助方法來獲取輸入數據并處理 **注解** 該類由系統自動加載,你無需手工加載 # 對輸入進行過濾 # 安全性過濾 當訪問 控制器 時,安全過濾方法會自動被調用, 它做了以下幾件事情: 如果 $config['allow_get_array'] 設置為 FALSE (默認是 TRUE),銷毀全局的 GET 數組。 當開啟 register_globals 時,銷毀所有的全局變量。 過濾 GET/POST/COOKIE 數據的鍵值,只允許出現字母和數字(和其他一些)字符。 提供了 XSS (跨站腳本攻擊)過濾,可全局啟用,或按需啟用。 將換行符統一為 PHP_EOL (基于 UNIX 的系統下為 \n,Windows 系統下為 \r\n),這個是可配置的。 XSS 過濾 輸入類可以自動的對輸入數據進行過濾,來阻止跨站腳本攻擊。如果你希望在每次遇到 POST 或 COOKIE 數據時自動運行過濾,你可以在 application/config/config.php 配置文件中設置如下參數: ~~~ $config['global_xss_filtering'] = TRUE; ~~~ 關于 XSS 過濾的信息,請參考 安全類 文檔。 **重要** 參數 'global_xss_filtering' 已經廢棄,保留它只是為了實現向前兼容。 XSS 過濾應該在*輸出*的時候進行,而不是*輸入*的時候! # 訪問表單數據 # 使用 POST、GET、COOKIE 和 SERVER 數據 CodeIgniter 提供了幾個輔助方法來從 POST、GET、COOKIE 和 SERVER 數組中獲取數據。 使用這些方法來獲取數據而不是直接訪問數組($_POST['something'])的最大的好處是, 這些方法會檢查獲取的數據是否存在,如果不存在則返回 NULL 。這使用起來將很方便, 你不再需要去檢查數據是否存在。換句話說,通常你需要像下面這樣做: ~~~ $something = isset($_POST['something']) ? $_POST['something'] : NULL; ~~~ 使用 CodeIgniter 的方法,你可以簡單的寫成: ~~~ $something = $this->input->post('something'); ~~~ 主要有下面幾個方法: ~~~ $this->input->post() $this->input->get() $this->input->cookie() $this->input->server() ~~~ # 使用 php://input 流 如果你需要使用 PUT、DELETE、PATCH 或其他的請求方法,你只能通過一個特殊的輸入流來訪問, 這個流只能被讀一次,這和從諸如 $_POST 數組中讀取數據相比起來要復雜一點,因為 POST 數組可以被訪問多次來獲取多個變量,而不用擔心它會消失。 CodeIgniter 為你解決了這個問題,你只需要使用下面的 $raw_input_stream 屬性即可, 就可以在任何時候讀取 php://input 流中的數據: ~~~ $this->input->raw_input_stream; ~~~ 另外,如果輸入流的格式和 $_POST 數組一樣,你也可以通過 input_stream() 方法來訪問它的值: ~~~ $this->input->input_stream('key'); ~~~ 和其他的 get() 和 post() 方法類似,如果請求的數據不存在,則返回 NULL 。 你也可以將第二個參數設置為 TRUE ,來讓數據經過 xss_clean() 的檢查: ~~~ $this->input->input_stream('key', TRUE); // XSS Clean $this->input->input_stream('key', FALSE); // No XSS filter ~~~ **注解** 你可以使用 method() 方法來獲取你讀取的是什么數據,PUT、DELETE 還是 PATCH 。 # 類參考 **class CI_Input** **$raw_input_stream** 返回只讀的 php://input 流數據。 該屬性可以被多次讀取。 * * * * * **post**([$index = NULL[, $xss_clean = NULL]]) 參數: * $index (mixed) -- POST parameter name * $xss_clean (bool) -- Whether to apply XSS filtering 返回: $_POST if no parameters supplied, otherwise the POST value if found or NULL if not 返回類型: mixed 第一個參數為你想要獲取的 POST 數據名: ~~~ $this->input->post('some_data'); ~~~ 如果獲取的數據不存在,該方法返回 NULL 。 第二個參數可選,用于決定是否使用 XSS 過濾器對數據進行過濾。 要使用過濾器,可以將第二個參數設置為 TRUE ,或者將 $config['global_xss_filtering'] 參數設置為 TRUE 。 ~~~ $this->input->post('some_data', TRUE); ~~~ 如果不帶任何參數該方法將返回 POST 中的所有元素。 如果希望返回 POST 所有元素并將它們通過 XSS 過濾器進行過濾, 可以將第一個參數設為 NULL ,第二個參數設為 TRUE ~~~ $this->input->post(NULL, TRUE); // returns all POST items with XSS filter $this->input->post(NULL, FALSE); // returns all POST items without XSS filter ~~~ 如果要返回 POST 中的多個元素,將所有需要的鍵值作為數組傳給它: ~~~ $this->input->post(array('field1', 'field2')); ~~~ 和上面一樣,如果希望數據通過 XSS 過濾器進行過濾,將第二個參數設置為 TRUE: ~~~ $this->input->post(array('field1', 'field2'), TRUE); ~~~ * * * * * **get**([$index = NULL[, $xss_clean = NULL]]) 參數: * $index (mixed) -- GET parameter name * $xss_clean (bool) -- Whether to apply XSS filtering 返回: $_GET if no parameters supplied, otherwise the GET value if found or NULL if not 返回類型: mixed 該函數和 post() 一樣,只是它用于獲取 GET 數據。 ~~~ $this->input->get('some_data', TRUE); ~~~ 如果不帶任何參數該方法將返回 GET 中的所有元素。 如果希望返回 GET 所有元素并將它們通過 XSS 過濾器進行過濾, 可以將第一個參數設為 NULL ,第二個參數設為 TRUE ~~~ $this->input->get(NULL, TRUE); // returns all GET items with XSS filter $this->input->get(NULL, FALSE); // returns all GET items without XSS filtering ~~~ 如果要返回 GET 中的多個元素,將所有需要的鍵值作為數組傳給它: ~~~ $this->input->get(array('field1', 'field2')); ~~~ 和上面一樣,如果希望數據通過 XSS 過濾器進行過濾,將第二個參數設置為 TRUE: ~~~ $this->input->get(array('field1', 'field2'), TRUE); ~~~ * * * * * **post_get**($index[, $xss_clean = NULL]) 參數: * $index (string) -- POST/GET parameter name * $xss_clean (bool) -- Whether to apply XSS filtering 返回: POST/GET value if found, NULL if not 返回類型: mixed 該方法和 post() 和 get() 方法類似,它會同時查找 POST 和 GET 兩個數組來獲取數據, 先查找 POST ,再查找 GET: ~~~ $this->input->post_get('some_data', TRUE); ~~~ * * * * * **get_post**($index[, $xss_clean = NULL]) 參數: * $index (string) -- GET/POST parameter name * $xss_clean (bool) -- Whether to apply XSS filtering 返回: GET/POST value if found, NULL if not 返回類型: mixed 該方法和 post_get() 方法一樣,只是它先查找 GET 數據: ~~~ $this->input->get_post('some_data', TRUE); ~~~ **注解** 這個方法在之前的版本中和 post_get() 方法是完全一樣的,在 CodeIgniter 3.0 中有所修改。 * * * * * **cookie**([$index = NULL[, $xss_clean = NULL]]) 參數: * $index (mixed) -- COOKIE name * $xss_clean (bool) -- Whether to apply XSS filtering 返回: $_COOKIE if no parameters supplied, otherwise the COOKIE value if found or NULL if not 返回類型: mixed 該方法和 post() 和 get() 方法一樣,只是它用于獲取 COOKIE 數據: ~~~ $this->input->cookie('some_cookie'); $this->input->cookie('some_cookie, TRUE); // with XSS filter ~~~ 如果要返回 COOKIE 中的多個元素,將所有需要的鍵值作為數組傳給它: ~~~ $this->input->cookie(array('some_cookie', 'some_cookie2')); ~~~ **注解** 和 Cookie 輔助函數 中的 get_cookie() 函數不同的是,這個方法不會根據 $config['cookie_prefix'] 來添加前綴。 * * * * * **server**($index[, $xss_clean = NULL]) 參數: * $index (mixed) -- Value name * $xss_clean (bool) -- Whether to apply XSS filtering 返回: $_SERVER item value if found, NULL if not 返回類型: mixed 該方法和 post() 、 get() 和 cookie() 方法一樣,只是它用于獲取 SERVER 數據: ~~~ $this->input->server('some_data'); ~~~ 如果要返回 SERVER 中的多個元素,將所有需要的鍵值作為數組傳給它: ~~~ $this->input->server(array('SERVER_PROTOCOL', 'REQUEST_URI')); ~~~ * * * * * **input_stream**([$index = NULL[, $xss_clean = NULL]]) 參數: * $index (mixed) -- Key name * $xss_clean (bool) -- Whether to apply XSS filtering 返回: Input stream array if no parameters supplied, otherwise the specified value if found or NULL if not 返回類型: mixed 該方法和 get() 、 post() 和 cookie() 方法一樣,只是它用于獲取 php://input 流數據。 * * * * * **set_cookie**($name = ''[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = NULL[, $httponly = NULL]]]]]]]) 參數: * $name (mixed) -- Cookie name or an array of parameters * $value (string) -- Cookie value * $expire (int) -- Cookie expiration time in seconds * $domain (string) -- Cookie domain * $path (string) -- Cookie path * $prefix (string) -- Cookie name prefix * $secure (bool) -- Whether to only transfer the cookie through HTTPS * $httponly (bool) -- Whether to only make the cookie accessible for HTTP requests (no JavaScript) 返回類型: void 設置 COOKIE 的值,有兩種方法來設置 COOKIE 值:數組方式和參數方式。 **數組方式** 使用這種方式,可以將第一個參數設置為一個關聯數組: ~~~ $cookie = array( 'name' => 'The Cookie Name', 'value' => 'The Value', 'expire' => '86500', 'domain' => '.some-domain.com', 'path' => '/', 'prefix' => 'myprefix_', 'secure' => TRUE ); $this->input->set_cookie($cookie); ~~~ **注意** 只有 name 和 value 兩項是必須的,要刪除 COOKIE 的話,將 expire 設置為空。 COOKIE 的過期時間是 秒 ,將它加到當前時間上就是 COOKIE 的過期時間。 記住不要把它設置成時間了,只要設置成距離當前時間的秒數即可,那么在這段 時間內,COOKIE 都將保持有效。如果將過期時間設置為 0 ,那么 COOKIE 只在 瀏覽器打開的期間是有效的,關閉后就失效了。 如果需要設置一個全站范圍內的 COOKIE ,而不關心用戶是如何訪問你的站點的, 可以將 domain 參數設置為你的 URL 前面以句點開頭,如:.your-domain.com path 參數通常不用設,上面的例子設置為根路徑。 prefix 只在你想避免和其他相同名稱的 COOKIE 沖突時才需要使用。 The httponly and secure flags, when omitted, will default to your $config['cookie_httponly'] and $config['cookie_secure'] settings. **參數方式** 如果你喜歡,你也可以使用下面的方式來設置 COOKIE: ~~~ $this->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure); ~~~ * * * * * **ip_address**() 返回: Visitor's IP address or '0.0.0.0' if not valid 返回類型: string 返回當前用戶的 IP 地址,如果 IP 地址無效,則返回 '0.0.0.0': ~~~ echo $this->input->ip_address(); ~~~ **重要** 該方法會根據 $config['proxy_ips'] 配置,來返回 HTTP_X_FORWARDED_FOR、 HTTP_CLIENT_IP、HTTP_X_CLIENT_IP 或 HTTP_X_CLUSTER_CLIENT_IP 。 * * * * * **valid_ip**($ip[, $which = '']) 參數: * $ip (string) -- IP address * $which (string) -- IP protocol ('ipv4' or 'ipv6') 返回: TRUE if the address is valid, FALSE if not 返回類型: bool 判斷一個 IP 地址是否有效,返回 TRUE/FALSE 。 **注解** 上面的 $this->input->ip_address() 方法會自動驗證 IP 地址的有效性。 ~~~ if ( ! $this->input->valid_ip($ip)) { echo 'Not Valid'; } else { echo 'Valid'; } ~~~ 第二個參數可選,可以是字符串 'ipv4' 或 'ipv6' 用于指定 IP 的格式,默認兩種格式都會檢查。 * * * * * **user_agent**([$xss_clean = NULL]) 返回: User agent string or NULL if not set 參數: $xss_clean (bool) -- Whether to apply XSS filtering 返回類型: mixed 返回當前用戶的用戶代理字符串(Web 瀏覽器),如果不可用則返回 FALSE 。 ~~~ echo $this->input->user_agent(); ~~~ 關于用戶代理的相關方法請參考 用戶代理類 。 * * * * * **request_headers**([$xss_clean = FALSE]) 參數: $xss_clean (bool) -- Whether to apply XSS filtering 返回: An array of HTTP request headers 返回類型: array 返回 HTTP 請求頭數組。當在非 Apache 環境下運行時, apache_request_headers() 函數不可用, 這個方法將很有用。 ~~~ $headers = $this->input->request_headers(); ~~~ * * * * * **get_request_header**($index[, $xss_clean = FALSE]) 參數: * $index (string) -- HTTP request header name * $xss_clean (bool) -- Whether to apply XSS filtering 返回: An HTTP request header or NULL if not found 返回類型: string 返回某個指定的 HTTP 請求頭,如果不存在,則返回 NULL 。 ~~~ $this->input->get_request_header('some-header', TRUE); ~~~ * * * * * **is_ajax_request**() 返回: TRUE if it is an Ajax request, FALSE if not 返回類型: bool 檢查服務器頭中是否含有 HTTP_X_REQUESTED_WITH ,如果有返回 TRUE ,否則返回 FALSE 。 * * * * * **is_cli_request**() 返回: TRUE if it is a CLI request, FALSE if not 返回類型: bool 檢查程序是否從命令行界面運行。 **注解** 該方法檢查當前正在使用的 PHP SAPI 名稱,同時檢查是否定義了 STDIN 常量, 來判斷當前 PHP 是否從命令行運行。 ~~~ $this->input->is_cli_request() ~~~ **注解** 該方法已經被廢棄,現在只是 is_cli() 函數的一個別名而已。 * * * * * **method**([$upper = FALSE]) 參數: $upper (bool) -- Whether to return the request method name in upper or lower case 返回: HTTP request method 返回類型: string 返回 $_SERVER['REQUEST_METHOD'] 的值,它有一個參數用于設置返回大寫還是小寫。 ~~~ echo $this->input->method(TRUE); // Outputs: POST echo $this->input->method(FALSE); // Outputs: post echo $this->input->method(); // Outputs: post ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看