簡體   English   中英

在mod_python中設置和讀取cookie(apache)

[英]setting and reading cookies in mod_python (apache)

我已經看過很多東西來解釋如何讀寫cookie,但是,我不知道如何在Apache的mod_python中做到這一點。 我嘗試將其放在我的HTML代碼的開頭,但是它說要放在HTTP標頭中。 我怎么做? 另外,如何檢索它們? 我最初主要在此站點上尋找: http : //webpython.codepoint.net/cgi_set_the_cookie

我的代碼當前是這樣開始的(它顯示為HTML的一部分)

Content-Type: text/html
Set-Cookie: test=1
<html>
    <head>

mod_python不是CGI,並提供了它自己的設置和讀取cookie的方式:

from mod_python import Cookie, apache
import time

def handler(req):
    # read a cookie
    spam_cookie = get_cookie(req, 'spam')

    # set a cookie
    egg_cookie = Cookie.Cookie('eggs', 'spam')
    egg_cookie.expires = time.time() + 300
    Cookie.add_cookie(req, egg_cookie)

    req.write('<html><head></head><body>There's a cookie</body></html>')
    return apache.OK

您可以在此處找到更多文檔: http : //www.modpython.org/live/current/doc-html/pyapi-cookie.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM