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

      編輯Tag賺U幣
      教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!

      推薦:cmd運(yùn)行php
      打開(kāi) 命令提示符 cmd.exe E:wampbinphpphp5.2.6php.exe a.php 11 11是傳參數(shù) 獲取 if($argv[1]){ $_GET['id']=$argv[1]; } echo $id=$_GET[id]+1; 你可以將 a.php 改成你的文件名, 注意目錄結(jié)構(gòu) 我這里直接使用 a.php 是因?yàn)?a.php 與 php.exe 是在同一個(gè)目錄下 為了方

        先確認(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ū)ο蟮慕涌冢琺emcached是為了降低動(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"

      分享:php分析域名
      php分析域名!寫(xiě)法方法!調(diào)用就可以得出域名 ? //轉(zhuǎn)載保留來(lái)源于http://www.hake.cc/span // ####################### 分析域名 ####################### function phpzygetname($url) { $referer = preg_replace(/https?://([^/]+).*/i, \1, $url); $referer = str_re

      共2頁(yè)上一頁(yè)12下一頁(yè)
      來(lái)源:模板無(wú)憂//所屬分類(lèi):PHP教程/更新時(shí)間:2013-04-17
      相關(guān)PHP教程