看板 ott
作者 ott (寶貝)
標題 HTTP COOKIES
時間 2011年05月23日 Mon. PM 07:56:54



http://210.70.179.219/cookie/HTTP-Cookies.htm

HTTP COOKIES



     
  • Cookies are a general mechanism which server side programs can use to store information on the client side. Subsequently, when the client requests the server again, it would

        send the cookies back to the server
  •  

     
  • Syntax of the Set-Cookie HTTP Response Header
       




    Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure
       




    NAME=VALUE       the name of the cookie variable
       




    expires=DATE          the expired date of the cookie
       




    domain=DOMAIN_NAME           The default value of domain is the host name of the server which generated the cookie response.
       




    path=PATH  The path attribute is used to specify the subset of URLs in a domain for which the cookie is valid. For example, The path "/xyz" would match "/xyzabc" and "/xyz/abc.htm". The path "/" is the most general path which matches any path.
       

    If the path is not specified, it as assumed to be the same path as the document being requested 
       




    secure


    If the secure option is set, the secure cookies will only be sent to HTTPS (HTTP over SSL) server.
       

       


       


           
    • NAME=VALUE 定義cookies


    •      


    • expires=DATE  所定義 cookies 之有效期
    •  

           
    • domain + path 表明所定義之 cookies 之有效範圍(那個server之那個應用)
         

               


    •    


     


  •  
  • When the client requests the server again, it would set the cookies back to the  

    server


        Cookie: NAME=VALUE;
     

       


  •  
  • Cookies are very often used to keep track of sessions needed by server side programs.
       

    ( 利用 cookie 紀錄 session id 存放在 client 端, 以便當clients向server之應用程式作請求時, client 附帶session id 到 server端來 ,  server端之平台及應用程式便可得知是那個client作請求)
  •  

 
  • PHP code : to set cookies 
     

        setcookie(name, value, expire, path, domain); 
       

    e.g. setcookie("user", "John", time()+3600, "/department1");
  •  

     
  • PHP code : to read cookies   




    use $_COOKIE array variable, 
       

    e.g. $_COOKIE["user"]



  •  
  • Try the following steps

       


           
    • telnet 210.70.179.219 80


    •      
    • GET /~srtsai/php/Login.php HTTP1.1  (enter

              enter)
       



             
    •    
     



  •  
    	
    	
     

    --
    ※ 編輯: ott 時間: 2011-05-23 19:58:37
    ※ 看板: ott 文章推薦值: 0 目前人氣: 0 累積人氣: 75 
    分享網址: 複製 已複製
    回到看板(←)《ott》
    guest
    x)推文 r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇