#!/usr/bin/python3
###################################################################################
# Set cookies
# Using HTTP header "Set-Cookie:"
# All cookies must be written before html output
###################################################################################
from urllib import parse

print('Content-Type: text/html')

print('Set-Cookie: fname=Sam')                                  #temporary cookie
print('Set-Cookie: greeting1=Hello_World; max-age=86400')       #expires after 1 full day

goodbye = parse.quote('Goodbye World/Adios')                    #encoded with %20 and %2F
print('Set-Cookie: greeting2=' + goodbye)                       #create the encoded cookie                    

print('\n')                                                     #required end of headers

print("""
<html>
    <body>
        <h1>Setting Cookies - Using HTTP Headers</h1>
        <h2>Some web page</h2>
        <h4>This page has set 3 cookies: 
        <br>'fname=Sam'
        <br>'greeting1=Hello_World'
        <br>'greeting2=Goodbye World/Adios'</h4>
    </body>
</html>
""")



#=== link to see the python code =================================================
import os, sys
sys.path.insert(0,'/home/s/sultans/web/python/demo')
import zCode                          #import func to display the Python code
filename = os.path.abspath(__file__)  #get absolute file name 
zCode.display(filename)               #call it
#=================================================================================