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

directory search
歡迎 目錄 快速參考圖 基本信息 服務(wù)器要求 許可協(xié)議 變更記錄 關(guān)于CodeIgniter 安裝 下載 CodeIgniter 安裝指導(dǎo) 從老版本升級 疑難解答 介紹 開始 CodeIgniter 是什么? CodeIgniter 速記表 支持特性 應(yīng)用程序流程圖 模型-視圖-控制器 架構(gòu)目標(biāo) 教程 內(nèi)容提要 加載靜態(tài)內(nèi)容 創(chuàng)建新聞條目 讀取新聞條目 結(jié)束語 常規(guī)主題 CodeIgniter URL 控制器 保留字 視圖 模型 輔助函數(shù) 使用 CodeIgniter 類庫 創(chuàng)建你自己的類庫 使用 CodeIgniter 適配器 創(chuàng)建適配器 創(chuàng)建核心系統(tǒng)類 鉤子 - 擴(kuò)展框架的核心 自動裝載資源 公共函數(shù) URI 路由 錯誤處理 緩存 調(diào)試應(yīng)用程序 以CLI方式運行 管理應(yīng)用程序 處理多環(huán)境 PHP替代語法 安全 開發(fā)規(guī)范 類庫參考 基準(zhǔn)測試類 日歷類 購物車類 配置類 Email 類 加密類 文件上傳類 表單驗證詳解 FTP 類 圖像處理類 輸入類 Javascript 類 語言類 裝載類 遷移類 輸出類 分頁類 模板解析器類 安全類 Session 類 HTML 表格類 引用通告類 排版類 單元測試類 URI 類 User-Agent 類 表單驗證 XML-RPC 和 XML-RPC 服務(wù)器 Zip 編碼類 緩存適配器 適配器參考 適配器 數(shù)據(jù)庫類 Active Record 類 數(shù)據(jù)庫緩存類 自定義函數(shù)調(diào)用 數(shù)據(jù)庫配置 連接你的數(shù)據(jù)庫 數(shù)據(jù)庫快速入門例子代碼 字段數(shù)據(jù) 數(shù)據(jù)庫維護(hù)類 查詢輔助函數(shù) 數(shù)據(jù)庫類 查詢 生成查詢記錄集 表數(shù)據(jù) 事務(wù) 數(shù)據(jù)庫工具類 JavaScript類 輔助函數(shù)參考 數(shù)組輔助函數(shù) CAPTCHA 輔助函數(shù) Cookie Helper 日期輔助函數(shù) 目錄輔助函數(shù) 下載輔助函數(shù) Email 輔助函數(shù) 文件輔助函數(shù) 表單輔助函數(shù) HTML輔助函數(shù) Inflector 輔助函數(shù) 語言輔助函數(shù) 數(shù)字輔助函數(shù) 路徑輔助函數(shù) 安全輔助函數(shù) 表情輔助函數(shù) 字符串輔助函數(shù) 文本輔助函數(shù) 排版輔助函數(shù) URL 輔助函數(shù) XML 輔助函數(shù)
characters

CodeIgniter 用戶指南 版本 2.1.0

編輯文檔、查看近期更改請 登錄 或 注冊  找回密碼
查看原文

輸入類

輸入類有兩個目的:

  1. 為了安全,預(yù)處理輸入數(shù)據(jù)。
  2. 提供helper的一些方法,取得輸入數(shù)據(jù),并預(yù)處理輸入數(shù)據(jù)。

說明: 系統(tǒng)自動加載此類,不用手動加載。

安全過濾(Security Filtering)

當(dāng)觸發(fā)一個控制器的時候,安全過濾(Security Filtering)功能自動啟動。做以下事情:

  • If $config['allow_get_array'] is FALSE(default is TRUE), destroys the global GET array.
  • 當(dāng) register_globals 被設(shè)置為 on 的時候,銷毀所有的全局變量。
  • 過濾 GET/POST/COOKIE 數(shù)組鍵,只允許字母-數(shù)字(以及一些其它的)字符。
  • 可以過濾跨站腳本攻擊 (Cross-site Scripting Hacks) 此功能可全局打開(enabled globally),或者按要求打開。
  • 換行符統(tǒng)一換為 \n(Windows 下為 \r\n)

跨站腳本(XSS)過濾

輸入類有能力阻止跨站腳本攻擊。如果你想讓過濾器遇到 POST 或者 COOKIE 數(shù)據(jù)時自動運行,你可以通過打開你的 application/config/config.php 文件進(jìn)行如下設(shè)置實現(xiàn):

$config['global_xss_filtering'] = TRUE;

請參考 安全類 文檔以獲得更多信息在你的應(yīng)用中使用跨站腳本過濾。

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

CodeIgniter 有3個 helper方法可以讓用戶取得POST, COOKIE 或 SERVER 的內(nèi)容。用這些方法比直接使用php方法($_POST['something'])的好處是不用先檢查此項目是不是存在。 直接使用php方法,必須先做如下檢驗:

if ( ! isset($_POST['something']))
{
????$something = FALSE;
}
else
{
????$something = $_POST['something'];
}

用CodeIgniter內(nèi)建的方法,你可以這樣:

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

這3個方法是:

  • $this->input->post()
  • $this->input->cookie()
  • $this->input->server()

$this->input->post()

第一個參數(shù)是所要取得的post中的數(shù)據(jù):

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

如果數(shù)據(jù)不存在,方法將返回 FALSE (布爾值)。

第二個參數(shù)是可選的,如果想讓取得的數(shù)據(jù)經(jīng)過跨站腳本過濾(XSS Filtering),把第二個參數(shù)設(shè)為TRUE。

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

To return an array of all POST items call without any parameters.

To return all POST items and pass them through the XSS filter set the first parameter NULL while setting the second parameter to boolean;

The function returns FALSE (boolean) if there are no items in the POST.

$this->input->post(NULL, TRUE); // returns all POST items with XSS filter
$this->input->post(); // returns all POST items without XSS filter

$this->input->get()

此方法類似post方法,用來取得get數(shù)據(jù):

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

如果沒有設(shè)置參數(shù)將返回GET的數(shù)組

如果第一參數(shù)為NULL,且第二參數(shù)為True,則返回經(jīng)過跨站腳本過濾(XSS Filtering)的數(shù)組。

如果沒有設(shè)從GET中取到數(shù)據(jù)將返回 FALSE (boolean)

$this->input->get(NULL, TRUE); // returns all GET items with XSS filter
$this->input->get(); // returns all GET items without XSS filtering

$this->input->get_post()

這個方法將會搜索POST和GET方式的數(shù)據(jù)流,首先以POST方式搜索,然后以GET方式搜索:

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

$this->input->cookie()

此方法類似post方法,用來取得cookie數(shù)據(jù):

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

$this->input->server()

此方法類似上面兩個方法,用來取得server數(shù)據(jù):

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

$this->input->set_cookie()

設(shè)置一個 Cookie 的值。這個函數(shù)接收兩種形式的參數(shù):數(shù)組形式和參數(shù)形式:

數(shù)組形式

用這種形式的話,第一個參數(shù)傳遞的是一個關(guān)聯(lián)數(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);

說明:

只有 name 和 value 是必須的??梢酝ㄟ^將 expire 設(shè)置成空來實現(xiàn)刪除 Cookie 的操作。

Cookie 的過期時間是以為單位來設(shè)置的,他是通過將 Cookie 的存續(xù)的時間值加上當(dāng)前系統(tǒng)時間來得到的。切記,expire 的值僅僅設(shè)置為Cookie 需要存續(xù)的時間長短,請不要將當(dāng)前的系統(tǒng)時間加上存續(xù)時間后再賦給變量。如果將 expire 設(shè)置成零,那么 Cookie 僅在瀏覽器關(guān)閉的時候失效。

For site-wide cookies regardless of how your site is requested, add your URL to the domain starting with a period, like this: .your-domain.com

The path is usually not needed since the function sets a root path.

The prefix is only needed if you need to avoid name collisions with other identically named cookies for your server.

The secure boolean is only needed if you want to make it a secure cookie by setting it to TRUE.

參數(shù)形式

If you prefer, you can set the cookie by passing data using individual parameters:

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

$this->input->ip_address()

返回當(dāng)前用戶的IP。如果IP地址無效,返回0.0.0.0的IP:

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

$this->input->valid_ip($ip)

測試輸入的IP地址是不是有效,返回布爾值TRUE或者FALSE。 注意:$this->input->ip_address()自動測試輸入的IP地址本身格式是不是有效。

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

$this->input->user_agent()

返回當(dāng)前用戶正在使用的瀏覽器的user agent信息。 如果不能得到數(shù)據(jù),返回FALSE。

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

See the User Agent Class for methods which extract information from the user agent string.

$this->input->request_headers()

在不支持apache_request_headers()的非Apache環(huán)境非常有用。返回請求頭(header)數(shù)組。

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

$this->input->get_request_header();

返回請求頭(request header)數(shù)組中某一個元素的值

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

$this->input->is_ajax_request()

檢查服務(wù)器頭HTTP_X_REQUESTED_WITH是否被設(shè)置,并返回布爾值。

$this->input->is_ajax_request()

$this->input->is_cli_request()

Checks to see if the STDIN constant is set, which is a failsafe way to see if PHP is being run on the command line.

$this->input->is_cli_request()

?

翻譯貢獻(xiàn)者: architectcom, Hex, hk_yuhe, IT不倒翁, soyota, sunjiaxi, xjflyttp, yinzhili, yzheng624, 暗夜星辰
最后修改: 2012-04-27 10:42:28
Previous article: Next article: