亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
Array Array Helper Benchmarking Benchmarking Class Caching Caching Driver Calendaring Calendaring Class CAPTCHA CAPTCHA Helper Config Config Class Cookie Cookie Helper Database Connecting to your Database Custom Function Calls Database Caching Class Database Configuration Database Forge Class Database Metadata Database Quick Start: Example Code Database Reference Database Utility Class DB Driver Reference Generating Query Results Queries Query Builder Class Query Helper Methods Transactions Date Date Helper Directory Directory Helper Download Download Helper Email Email Class Email Helper Encrypt Encrypt Class Encryption Encryption Library File File Helper File Uploading File Uploading Class Form Form Helper Form Validation Form Validation FTP FTP Class Functions compatibility_functions common_functions HTML HTML Helper HTML Table HTML Table Class Image Manipulation Image Manipulation Class Inflector Inflector Helper Input Input Class Javascript Javascript Class Language Language Class Language Helper Loader Loader Class Migrations Migrations Class Number Number Helper Output Output Class Pagination Pagination Class Path Path Helper Security Security Class Security Helper Session Session Library Shopping Cart Shopping Cart Class Smiley Smiley Helper String String Helper Template Parser Template Parser Class Text Text Helper Trackback Trackback Class Typography Typography Class Typography Helper Unit Testing Unit Testing Class URI URL User Agent XML XML-RPC and XML-RPC Server Zip Encoding Zip Encoding Class XML-RPC and XML-RPC Server Classes XML Helper User Agent Class URL Helper URI Class
characters

輸入類有兩個目的:

  1. 它預(yù)處理全局輸入數(shù)據(jù)以確保安全。

  2. 它提供了一些輔助方法來獲取輸入數(shù)據(jù)并對其進(jìn)行預(yù)處理。

注意

該類由系統(tǒng)自動初始化,因此不需要手動執(zhí)行。

  • 輸入過濾

    • 安全篩選

    • XSS過濾

  • 訪問表單數(shù)據(jù)

    • 使用POST,GET,COOKIE或SERVER數(shù)據(jù)

    • 使用php://輸入流

  • 類參考

輸入過濾

安全篩選

當(dāng)調(diào)用新的控制器時,將自動調(diào)用安全過濾方法。它執(zhí)行以下操作:

  • 如果$config['allow_get_array']為FALSE(默認(rèn)值為TRUE),則會銷毀全局GET數(shù)組。

  • 銷毀register_globals處于打開狀態(tài)的所有全局變量。

  • 過濾GET / POST / COOKIE數(shù)組鍵,僅允許字母數(shù)字(和其他幾個字符)。

  • 提供XSS(跨站腳本攻擊)過濾。這可以在全球啟用,或根據(jù)要求啟用。

  • 將換行符標(biāo)準(zhǔn)化為PHP_EOL(在基于UNIX的操作系統(tǒng)中為\ n,在Windows下為\ r \ n)。這是可配置的。

XSS過濾

Input類可以自動過濾輸入以防止跨站腳本攻擊。如果您希望篩選器在每次遇到POST或COOKIE數(shù)據(jù)時自動運行,您可以通過打開application / config / config.php文件并設(shè)置它來啟用它:

$config['global_xss_filtering'] = TRUE;

有關(guān)在您的應(yīng)用程序中使用XSS Filtering的信息,請參閱Security類文檔。

重要

'global_xss_filtering'設(shè)置為DEPRECATED,僅用于向后兼容的目的。應(yīng)該在輸出上執(zhí)行XSS轉(zhuǎn)義,而不是輸入

訪問表單數(shù)據(jù)

使用POST,GET,COOKIE或SERVER數(shù)據(jù)

CodeIgniter帶有助手方法,可以讓你獲取POST,GET,COOKIE或SERVER項目。使用提供的方法而不是直接獲取項目的主要優(yōu)點$_POST['something']是方法將檢查項目是否設(shè)置,如果不是,則返回NULL。這使您可以方便地使用數(shù)據(jù),而不必先測試項目是否存在。換句話說,通常你可能會這樣做:

$something = isset($_POST['something']) ? $_POST['something'] : NULL;

使用CodeIgniter的內(nèi)置方法,您可以簡單地執(zhí)行此操作:

$something = $this->input->post('something');

主要方法是:

  • $this->input->post()

  • $this->input->get()

  • $this->input->cookie()

  • $this->input->server()

Using the php://input stream

如果你想利用PUT,DELETE,PATCH或其他奇特的請求方法,它們只能通過一個特殊的輸入流來訪問,它只能被讀取一次。這不像從$_POST數(shù)組讀取那樣簡單,因為它會一直存在,并且您可以嘗試訪問多個變量,而不必關(guān)心在所有POST數(shù)據(jù)中只能有一個鏡頭。

CodeIgniter會為你處理這個問題,你可以隨時從php://輸入流中讀取數(shù)據(jù),只需使用$raw_input_stream屬性:

$this->input->raw_input_stream;

另外,如果輸入流像$ _POST一樣進(jìn)行表單編碼,則可以通過調(diào)用input_stream()方法來訪問其值:

$this->input->input_stream('key');

類似于其他方法,如get()post(),如果未找到所請求的數(shù)據(jù),它會返回NULL,你也可以決定是否通過運行數(shù)據(jù)xss_clean()通過傳遞一個布爾值作為第二個參數(shù):

$this->input->input_stream('key', TRUE); // XSS Clean$this->input->input_stream('key', FALSE); // No XSS filter

注意

您可以利用method()以了解您是否正在讀取PUT,DELETE或PATCH數(shù)據(jù)。

類參考

class CI_Input$raw_input_stream

只讀屬性將返回php://輸入數(shù)據(jù)原樣。

該屬性可以多次讀取。

post([$index = NULL[, $xss_clean = NULL]])

參數(shù):

$ index(mixed) -  POST參數(shù)名稱$ xss_clean(bool) - 是否應(yīng)用XSS過濾

返回:

$ _POST如果沒有提供參數(shù),否則POST值如果找到,否則返回NULL

返回類型:

  • $ indexmixed) -  POST參數(shù)名稱

  • $ xss_cleanbool) - 是否應(yīng)用XSS過濾

Returns:  $\_POST if no parameters supplied, otherwise the POST value if found or NULL if not
Return type:  mixed
第一個參數(shù)將包含您正在查找的POST項目的名稱:

$this->input->post('some_data');

如果您嘗試檢索的項目不存在,則該方法返回NULL。

第二個可選參數(shù)允許您通過XSS過濾器運行數(shù)據(jù)。通過將第二個參數(shù)設(shè)置為布爾TRUE或?qū)⑵湓O(shè)置$config['global_xss_filtering']為TRUE 來啟用它。

$this->input->post('some_data', TRUE);

要返回一個沒有任何參數(shù)的所有POST項目調(diào)用的數(shù)組。

要返回所有POST項目并將它們傳遞給XSS篩選器,請將第一個參數(shù)設(shè)置為NULL,同時將第二個參數(shù)設(shè)置為布爾值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參數(shù)的數(shù)組,請將所有必需的鍵作為數(shù)組傳遞。

$this->input->post(array('field1', 'field2'));

在這里應(yīng)用相同的規(guī)則,為了檢索啟用了XSS過濾的參數(shù),將第二個參數(shù)設(shè)置為布爾TRUE。

$this->input->post(array('field1', 'field2'), TRUE);

get([$index = NULL[, $xss_clean = NULL]])

參數(shù):

$ index(mixed) -  GET參數(shù)名稱$ xss_clean(bool) - 是否應(yīng)用XSS過濾

返回:

$ _GET如果沒有提供參數(shù),否則GET值如果找到,否則返回NULL

返回類型:

  • $ indexmixed) -  GET參數(shù)名稱

  • $ xss_cleanbool) - 是否應(yīng)用XSS過濾

Returns:  $\_GET if no parameters supplied, otherwise the GET value if found or NULL if not
Return type:  mixed
This method is identical to `post()`, only it fetches GET data.

$this->input->get('some_data', TRUE);

不帶任何參數(shù)返回所有GET項目數(shù)組的調(diào)用。

要返回所有GET項并將它們傳遞給XSS篩選器,請將第一個參數(shù)設(shè)置為NULL,同時將第二個參數(shù)設(shè)置為布爾值TRUE。

$ this-> input-> get(NULL,TRUE); //返回帶有XSS過濾器的所有GET項目$ this-> input-> get(NULL,F(xiàn)ALSE); //返回所有沒有XSS過濾的GET項目

要返回多個GET參數(shù)的數(shù)組,請將所有必需的鍵作為數(shù)組傳遞。

$this->input->get(array('field1', 'field2'));

在這里應(yīng)用相同的規(guī)則,為了檢索啟用了XSS過濾的參數(shù),將第二個參數(shù)設(shè)置為布爾TRUE。

$this->input->get(array('field1', 'field2'), TRUE);

post_get($index[, $xss_clean = NULL])

參數(shù):

$ index(string) -  POST / GET參數(shù)名稱$ xss_clean(bool) - 是否應(yīng)用XSS過濾

返回:

如果找到POST / GET值,則返回NULL

返回類型:

  • $ indexstring) -  POST / GET參數(shù)名稱

  • $ xss_cleanbool) - 是否應(yīng)用XSS過濾

Returns:  POST/GET value if found, NULL if not
Return type:  mixed
This method works pretty much the same way as `post()` and `get()`, only combined. It will search through both POST and GET streams for data, looking in POST first, and then in GET:

$this->input->post_get('some_data', TRUE);

get_post($index[, $xss_clean = NULL])

參數(shù):

$ index(string) -  GET / POST參數(shù)名稱$ xss_clean(bool) - 是否應(yīng)用XSS過濾

返回:

如果找到GET / POST值,則返回NULL

返回類型:

  • $ indexstring) -  GET / POST參數(shù)名稱

  • $ xss_cleanbool) - 是否應(yīng)用XSS過濾

Returns:  GET/POST value if found, NULL if not
Return type:  mixed
This method works the same way as `post_get()` only it looks for GET data first.

$this->input->get_post(‘some_data’, TRUE);  Note

此方法用于post_get()表現(xiàn)得很像,但它的行為在CodeIgniter 3.0中發(fā)生了變化。

cookie([$index = NULL[, $xss_clean = NULL]])

參數(shù):

$ index(混合) -  COOKIE名稱$ xss_clean(bool) - 是否應(yīng)用XSS過濾

返回:

如果沒有提供參數(shù),則返回$ _COOKIE,否則返回COOKIE值,否則返回NULL

返回類型:

  • $ index混合) -  COOKIE名稱

  • $ xss_cleanbool) - 是否應(yīng)用XSS過濾

Returns:  $\_COOKIE if no parameters supplied, otherwise the COOKIE value if found or NULL if not
Return type:  mixed
This method is identical to `post()` and `get()`, only it fetches cookie data:

$this->input->cookie('some_cookie'); $this->input->cookie('some_cookie, TRUE); // with XSS filter

要返回多個Cookie值的數(shù)組,請將所有必需的鍵作為數(shù)組傳遞。

$this->input->cookie(array('some_cookie', 'some_cookie2'));

注意

與Cookie幫助器函數(shù)不同get_cookie(),此方法不會預(yù)先配置您的配置$config['cookie_prefix']值。

server($index[, $xss_clean = NULL])

參數(shù):

$ index(mixed) - 值名稱$ xss_clean(bool) - 是否應(yīng)用XSS過濾

返回:

如果找到$ _SERVER項目值,則返回NULL

返回類型:

  • $ index混合) - 值名稱

  • $ xss_cleanbool) - 是否應(yīng)用XSS過濾

Returns:  $\_SERVER item value if found, NULL if not
Return type:  mixed
This method is identical to the `post()`, `get()` and `cookie()` methods, only it fetches server data (`$_SERVER`):

$this->input->server('some_data');

要返回多個$_SERVER值的數(shù)組,請將所有必需的鍵作為數(shù)組傳遞。

$this->input->server(array('SERVER_PROTOCOL', 'REQUEST_URI'));

input_stream([$index = NULL[, $xss_clean = NULL]])

參數(shù):

$ index(mixed) - 鍵名$ xss_clean(bool) - 是否應(yīng)用XSS過濾

返回:

輸入流數(shù)組,如果沒有提供參數(shù),否則指定的值如果找到,否則返回NULL

返回類型:

  • $ index混合) - 密鑰名稱

  • $ xss_cleanbool) - 是否應(yīng)用XSS過濾

Returns:  Input stream array if no parameters supplied, otherwise the specified value if found or NULL if not
Return type:  mixed
This method is identical to `get()`, `post()` and `cookie()`, only it fetches the _php://input_ stream data.

set_cookie($name = ''[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = NULL[, $httponly = NULL]]]]]]])

參數(shù):

$ name(字符串) -  Cookie值$ expire(int) -  Cookie過期時間(以秒為單位)$ domain(字符串) -  Cookie域$ path(字符串) -  Cookie路徑$ prefix (字符串) -  Cookie名稱前綴$ secure(bool) - 是否僅通過HTTPS傳輸cookie $ httponly(bool) - 是否僅允許HTTP請求訪問Cookie(無JavaScript)

返回類型:

void

  • $ name混合) -  Cookie名稱或參數(shù)數(shù)組

  • $ value字符串) -  Cookie值

  • $ expireint) - 以秒為單位的Cookie過期時間

  • $域字符串) -  Cookie域

  • $ pathstring) -  Cookie路徑

  • $ prefix字符串) -  Cookie名稱前綴

  • $ securebool) - 是否僅通過HTTPS傳輸cookie

  • $ httponlybool) - 是否僅允許HTTP請求訪問cookie(無JavaScript)

Return type:  void
Sets a cookie containing the values you specify. There are two ways to pass information to this method so that a cookie can be set: Array Method, and Discrete Parameters:

數(shù)組方法

使用這種方法,將關(guān)聯(lián)數(shù)組傳遞給第一個參數(shù):

$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);

筆記

只有名字和價值是必需的。要刪除cookie,將其設(shè)置為過期空白。

到期時間以為單位設(shè)置,并將添加到當(dāng)前時間。不要包含時間,而只需要從現(xiàn)在起您希望cookie有效的秒數(shù)。如果過期設(shè)置為零,則只有在瀏覽器處于打開狀態(tài)時,cookie才會持續(xù)。

無論網(wǎng)站的請求方式如何,對于站點級的Cookie,請將您的網(wǎng)址添加到以句點開頭的網(wǎng),如下所示:.your-domain.com

由于該方法設(shè)置了根路徑,因此通常不需要該路徑。

只有當(dāng)您需要避免與服務(wù)器上其他名稱相同的cookie發(fā)生名稱沖突時,才需要前綴。

僅Http安全標(biāo)志,省略時,將默認(rèn)為您$config['cookie_httponly']$config['cookie_secure']設(shè)置。

離散參數(shù)

如果您愿意,可以通過使用各個參數(shù)傳遞數(shù)據(jù)來設(shè)置Cookie:

$ this-> input-> set_cookie($ name,$ value,$ expire,$ domain,$ path,$ prefix,$ secure);

ip_address()

返回:

訪問者的IP地址或“0.0.0.0”,如果無效

返回類型:

valid_ip($ip[, $which = ''])

參數(shù):

$ ip(string) -  IP地址$ which(string) -  IP協(xié)議('ipv4'或'ipv6')

返回:

如果地址有效則為TRUE,否則為FALSE

返回類型:

布爾

  • $ ip字符串) -  IP地址

  • $ whichstring) -  IP協(xié)議('ipv4'或'ipv6')

Returns:  TRUE if the address is valid, FALSE if not
Return type:  bool
Takes an IP address as input and returns TRUE or FALSE (boolean) depending on whether it is valid or not.

注意

上面的$ this-> input-> ip_address()方法自動驗證IP地址。

if ( ! $this->input->valid_ip($ip)) {         echo 'Not Valid'; } else {         echo 'Valid'; }

接受可選的第二個字符串參數(shù)'ipv4'或'ipv6'來指定IP格式。這兩種格式的默認(rèn)檢查。

user_agent([$xss_clean = NULL])

返回:

用戶代理字符串,如果未設(shè)置,則為NULL

參數(shù):

$ xss_clean(bool) - 是否應(yīng)用XSS過濾

返回類型:

  • $ xss_cleanbool) - 是否應(yīng)用XSS過濾

Return type:  mixed
Returns the user agent string (web browser) being used by the current user, or NULL if it’s not available.

echo $this->input->user_agent();

有關(guān)從用戶代理字符串提取信息的方法,請參閱用戶代理類。

request_headers([$xss_clean = FALSE])

參數(shù):

$ xss_clean(bool) - 是否應(yīng)用XSS過濾

返回:

一組HTTP請求標(biāo)頭

返回類型:

排列

  • $ xss_cleanbool) - 是否應(yīng)用XSS過濾

Returns:  An array of HTTP request headers
Return type:  array
Returns an array of HTTP request headers. Useful if running in a non-Apache environment where [apache\_request\_headers()](https://php.net/apache_request_headers) will not be supported.

$headers = $this->input->request_headers();

get_request_header($index[, $xss_clean = FALSE])

參數(shù):

$ index(string) -  HTTP請求頭名稱$ xss_clean(bool) - 是否應(yīng)用XSS過濾

返回:

HTTP請求標(biāo)頭或NULL,如果未找到

返回類型:

  • $ indexstring) -  HTTP請求標(biāo)題名稱

  • $ xss_cleanbool) - 是否應(yīng)用XSS過濾

返回:HTTP請求標(biāo)頭或NULL,如果未找到
Return type:  string
Returns a single member of the request headers array or NULL if the searched header is not found.

$this->input->get_request_header('some-header', TRUE);

is_ajax_request()

返回:

如果它是Ajax請求則為TRUE,否則為FALSE

返回類型:

布爾

is_cli_request()

返回:

如果是CLI請求則為TRUE,否則為FALSE

返回類型:

布爾

method([$upper = FALSE])

參數(shù):

$ upper(bool) - 是否以大寫或小寫形式返回請求方法名稱

返回:

HTTP請求方法

返回類型:

  • $ upperbool) - 是否以大寫或小寫形式返回請求方法名稱

Returns:  HTTP request method
Return type:  string
Returns the `$_SERVER['REQUEST_METHOD']`, with the option to set it in uppercase or lowercase.

echo $this->input->method(TRUE); // Outputs: POST echo $this->input->method(FALSE); // Outputs: post echo $this->input->method(); // Outputs: post

Previous article: Next article: