国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > PHP > 正文

詳解PHP會(huì)話存儲(chǔ)方式

2024-05-04 21:53:09
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

  先確認(rèn)會(huì)話是否自動(dòng)開(kāi)啟還是需要通過(guò)session_start()來(lái)手動(dòng)開(kāi)啟:

  ; 指定會(huì)話模塊是否在請(qǐng)求開(kāi)始時(shí)自動(dòng)啟動(dòng)一個(gè)會(huì)話。默認(rèn)為 0(不啟動(dòng))

  ; Initialize session on request startup.

  ; http://php.net/session.auto-start

  session.auto_start = 0

  在客戶端,會(huì)話可以存儲(chǔ)在cookie或者通過(guò)URL參數(shù)來(lái)獲取。依賴于服務(wù)器的配置:

  ; 指定是否在客戶端用 cookie 來(lái)存放會(huì)話 ID。默認(rèn)為 1(啟用)

  ; Whether to use cookies.

  ; http://php.net/session.use-cookies

  session.use_cookies = 1

  ; 指定是否在客戶端僅僅使用 cookie 來(lái)存放會(huì)話 ID。。啟用此設(shè)定可以防止有關(guān)通過(guò) URL 傳遞會(huì)話 ID 的攻擊。

  ; This option forces PHP to fetch and use a cookie for storing and maintaining

  ; the session id. We encourage this operation as it's very helpful in combatting

  ; session hijacking when not specifying and managing your own session id. It is

  ; not the end all be all of session hijacking defense, but it's a good start.

  ; http://php.net/session.use-only-cookies

  session.use_only_cookies = 1

  如果確認(rèn)存儲(chǔ)在cookie中,則可以進(jìn)一點(diǎn)配置會(huì)話存儲(chǔ)在cookie中的各項(xiàng)配置,如cookie_name,cookie_lifetime,cookie_path,cookie_domain,cookie_secure,cookie_httponly

  ; Name of the session (used as cookie name).

  ; http://php.net/session.name

  session.name = PHPSESSID

  ; Lifetime in seconds of cookie or, if 0, until browser is restarted.

  ; http://php.net/session.cookie-lifetime

  session.cookie_lifetime = 0

  ; The path for which the cookie is valid.

  ; http://php.net/session.cookie-path

  session.cookie_path = /

  ; The domain for which the cookie is valid.

  ; http://php.net/session.cookie-domain

  session.cookie_domain =

  ; Whether or not to add the httpOnly flag to the cookie, which makes it inaccessible to browser scripting languages such as JavaScript.

  ; http://php.net/session.cookie-httponly

  session.cookie_httponly =

  在服務(wù)器端,同樣也可以通過(guò)多種方式來(lái)存儲(chǔ)會(huì)話。默認(rèn)會(huì)話存儲(chǔ)在文件中,此時(shí)session.save_path為創(chuàng)建存儲(chǔ)文件的路徑。

  ; Handler used to store/retrieve data.

  ; http://php.net/session.save-handler

  session.save_handler = files

  ; Argument passed to save_handler. In the case of files, this is the path

  ; where data files are stored. Note: Windows users have to change this

  ; variable in order to use PHP

  's session functions.

  ;

  ; The path can be defined as:

  ;

  ; session.save_path = "N;/path"

  ;

  ; where N is an integer. Instead of storing all the session files in

  ; /path, what this will do is use subdirectories N-levels deep, and

  ; store the session data in those directories. This is useful if you

  ; or your OS have problems with lots of files in one directory, and is

  ; a more efficient layout for servers that handle lots of sessions.

  ;

  ; NOTE 1: PHP will not create this directory structure automatically.

  ; You can use the script in the ext/session dir for that purpose.

  ; NOTE 2: See the section on garbage collection below if you choose to

  ; use subdirectories for session storage

  ;

  ; The file storage module creates files using mode 600 by default.

  ; You can change that by using

  ;

  ; session.save_path = "N;MODE;/path"

  ;

  ; where MODE is the octal representation of the mode. Note that this

  ; does not overwrite the process's umask.

  ; http://php.net/session.save-path

  ;session.save_path = "/tmp"

  PHP支持通過(guò)session_set_save_handler來(lái)實(shí)現(xiàn)會(huì)話處理器的自定義open, close, read, write, destroy, gc處理函數(shù),常見(jiàn)的會(huì)話處理器包括使用內(nèi)存型分配(如mm,memcache等),也可以使用數(shù)據(jù)庫(kù)進(jìn)行存儲(chǔ)。由此可見(jiàn),若需要會(huì)話存儲(chǔ)與文件系統(tǒng)(例如用數(shù)據(jù)庫(kù)PostgreSQL Session Save Handler或默認(rèn)的文件存儲(chǔ)files)協(xié)同工作的,此時(shí)有可能造成用戶定制的會(huì)話處理器丟失了未存儲(chǔ)數(shù)據(jù)的會(huì)話。若使用內(nèi)存型分配存儲(chǔ),又需要考慮會(huì)話持久化存儲(chǔ)問(wèn)題。

  接下來(lái)重點(diǎn)講解memcache(d?)會(huì)話處理器。

  Memcache模塊提供了于memcached方便的面向過(guò)程及面向?qū)ο蟮慕涌?,memcached是為了降低動(dòng)態(tài)web應(yīng)用 從數(shù)據(jù)庫(kù)加載數(shù)據(jù)而產(chǎn)生的一種常駐進(jìn)程緩存產(chǎn)品。

  Memcache模塊同時(shí)提供了一個(gè)session 處理器 (memcache).

  更多關(guān)于memcached的信息請(qǐng)參見(jiàn)» http://www.memcached.org/.

  memcached是一個(gè)高性能分布式的內(nèi)存對(duì)象緩存系統(tǒng), 通常被用于降低數(shù)據(jù)庫(kù)加載壓力以提高動(dòng)態(tài)web應(yīng)用的響應(yīng)速度。

  此擴(kuò)展使用了libmemcached庫(kù)提供的api與memcached服務(wù)端進(jìn)行交互。它同樣提供了一個(gè)session處理器(memcached)。 它同時(shí)提供了一個(gè)session處理器(memcached)。

  關(guān)于libmemcached的更多信息可以在» http://libmemcached.org/libMemcached.html查看。

  memcache會(huì)話處理器配置:

  session.save_handler = memcache

  session.save_path = "tcp://127.0.0.1:11211?persistent=0&weight=1&timeout=1&retry_interval=15,tcp://127.0.0.1:11212?persistent=0&weight=1&timeout=1&retry_interval=15,tcp://127.0.0.1:11213?persistent=0&weight=1&timeout=1&retry_interval=15,tcp://127.0.0.1:11214?persistent=0&weight=1&timeout=1&retry_interval=15"

共2頁(yè)上一頁(yè)12下一頁(yè)
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 东台市| 奉新县| 齐齐哈尔市| 大余县| 定远县| 罗定市| 淮阳县| 莒南县| 金秀| 西林县| 福海县| 郧西县| 遂川县| 化州市| 浙江省| 曲松县| 泽库县| 山丹县| 阳朔县| 平南县| 肥乡县| 武功县| 永顺县| 岑巩县| 古田县| 连平县| 尼勒克县| 汉寿县| 临沧市| 花莲县| 永新县| 乌兰浩特市| 台北市| 巴楚县| 眉山市| 舟山市| 江孜县| 江安县| 桓台县| 叶城县| 盐亭县|