CodeIgniter
  • 歡迎加入 CodeIgniter
  • 安裝指引
    • 下載 CodeIgniter
    • 安裝指引
    • 從先前的版本來更新
    • 故障排除
  • CodeIgniter 概觀
    • 開始 CodeIgniter
    • CodeIgniter 一目了然
    • CodeIgniter 特色
    • 應用程式溝通流程
    • Model-View-Controller
    • 設計以及架構目標
  • 教學
    • 靜態頁面
    • 新聞模組介紹
    • 動態新增新聞
    • 結論
  • 一般主題
    • CodeIgniter URLs
    • 控制器 Controllers
    • 保留名稱
    • 視圖 Views
    • 什麼是 Model?
    • 剖析 Model
    • 載入 Model
    • 自動載入 Models
    • 連接資料庫
    • Helpers
    • 使用 CodeIgniter 函式庫
    • 自建函式庫
    • 使用 CodeIgniter 驅動器
    • 自建驅動器
    • 新增系統核心類別
    • 新增配套類別
    • Hooks-擴充核心
    • 自動載入資源
    • 通用函數
    • 相容性函數
    • URI 路由
    • 錯誤處理
    • Caching
    • 應用程式效能分析
    • 透過 CLI 執行 CodeIgniter
    • 管理你的應用程式
    • 處理多環境變數
    • 替代 View 檔案的 PHP 的語法
    • 安全性
    • PHP Style Guide
  • Libraries
    • 效能測試類別
    • 快取驅動類別
    • 日曆類別
    • 購物車類別
    • 設定類別
    • 電子郵件類別
    • Encrypt Class
    • Encryption Library
    • 檔案上傳類別
    • Form Validation
    • FTP Class
    • Image Manipulation Class
    • Input Class
    • Javascript Class
    • Language Class
    • Loader Class
    • Migrations Class
    • Output Class
    • Pagination Class
    • Template Parser Class
    • Security Class
    • Session Library
    • HTML Table 類別
    • Trackback 類別
    • Typography 類別
    • 單元測試類別
    • URI 類別
    • User Agent 類別
    • XML-RPC 及 XML-RPC Server 類別
    • Zip 類別
  • 資料庫參考
    • 快速入門:範例程式
    • 資料庫設定
    • 連接資料庫
    • 執行查詢
    • 產生查詢結果
    • 查詢補助函數
    • 查詢生成器類別
    • 交易
    • 取得資料表資訊
    • 自訂函數
    • 查詢快取
    • 使用 Database Forge 管理資料庫
    • Database Utilities 類別
    • Database Driver 參考
  • 輔助函式
    • Array 輔助函式
    • CAPTCHA 輔助函式
    • Cookie 輔助函式
    • Date 輔助函式
    • Directory 輔助函式
    • Download 輔助函式
    • Email 輔助函式
    • File 輔助函式
    • Form 輔助函式
    • HTML 輔助函式
    • Inflector 輔助函式
    • Language 輔助函式
    • Number 輔助函式
    • Path 輔助函式
    • Security 輔助函式
    • Smiley 輔助函式
    • String 輔助函式
    • Text 輔助函式
    • Typography 輔助函式
    • URL 輔助函式
    • XML 輔助函式
  • 貢獻 CodeIgniter
    • Writing CodeIgniter Documentation
    • Developer’s Certificate of Origin 1.1
 
CodeIgniter
  • 使用手冊 »
  • 輔助函式 »
  • Cookie 輔助函式

Cookie 輔助函式¶

Cookie 輔助函式包含了各種輔助使用 Cookie 的相關函式。

  • 導入輔助函式
  • 可用函式格式

導入輔助函式¶

Cookie 輔助函式的載入語法如下:

$this->load->helper('cookie');

可用函式格式¶

允許使用的函式格式如下:

set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = NULL[, $httponly = NULL]]]]]]])¶
Parameters:
  • $name (mixed) – Cookie 名稱或包含函式中所有有效參數的陣列
  • $value (string) – Cookie 值
  • $expire (int) – 有效期限秒數
  • $domain (string) – Cookie 網域名稱(通常是:.yourdomain.com)
  • $path (string) – Cookie 路徑
  • $prefix (string) – Cookie 名稱前綴
  • $secure (bool) – 是否只透過 HTTPS 傳送 Cookie
  • $httponly (bool) – 是否對 JavaScript 隱藏 Cookie
Return type:

不回傳任何值

此輔助函式對於設置 Cookie 提供了相當友善的語法,可以參考 Input Library 敘述中所提到的用法,此函式相當於就是 CI_Input::set_cookie() 的別名。

get_cookie($index[, $xss_clean = NULL])¶
Parameters:
  • $index (string) – Cookie 名稱
  • $xss_clean (bool) – 是否對回傳值啟用 XSS 過濾機制
Returns:

Cookie 的值或沒有找到就回傳 NULL

Return type:

各種型態皆有

此輔助函式對於取得 Cookie 提供了相當友善的語法,可以參考 Input Library 敘述中所提到的用法。此函式執行起來雖與 CI_Input::cookie() 很相像,但除此之外會加入你在 application/config/config.php 檔案中所設置的前綴 $config['cookie_prefix']。

delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]])¶
Parameters:
  • $name (string) – Cookie 名稱
  • $domain (string) – Cookie 網域名稱(通常是:.yourdomain.com)
  • $path (string) – Cookie 路徑
  • $prefix (string) – Cookie 名稱前綴
Return type:

void

刪除 Cookie 時,除非你指定了路徑或其他值,否則只有具有 name 的 Cookie 會被刪除。

delete_cookie('name');

此函式在格式上除了沒有 value 跟 expire 這兩個參數之外,其實與 set_cookie() 不盡相同。你可以只對第一個參數送出一個的陣列或者你也可以個別設置參數。

delete_cookie($name, $domain, $path, $prefix);
下一頁 上一頁

© Copyright 2014 - 2017, British Columbia Institute of Technology. 最後編輯時間 Nov 19, 2020.

由 Read the Docs 提供 Sphinx 並使用 sphinx_rtd_theme 主題

Github 繁體中文翻譯