การส่งคุกกี้ไปยังเบราว์เซอร์ทำได้ง่ายมาก คุกกี้เหล่านี้ถูกส่งพร้อมกับ HTTP Header ก่อนฟิลด์ Content-type สมมติว่าต้องการตั้งค่า UserID และ Password เป็นคุกกี้ การตั้งค่าคุกกี้ทำดังนี้:
ตัวอย่างโค้ด
#!/usr/bin/python print "Set-Cookie:UserID = XYZ;\r\n" print "Set-Cookie:Password = XYZ123;\r\n" print "Set-Cookie:Expires = Tuesday, 31-Dec-2007 23:12:40 GMT";\r\n" print "Set-Cookie:Domain = www.tutorialspoint.com;\r\n" print "Set-Cookie:Path = /perl;\n" print "Content-type:text/html\r\n\r\n" ...........Rest of the HTML Content....
จากตัวอย่างนี้ คุณควรเข้าใจแล้วว่าตั้งคุกกี้อย่างไร เราใช้ HTTP header Set-Cookie เพื่อตั้งคุกกี้
การตั้งค่าแอตทริบิวต์คุกกี้เช่น Expires, Domain, และ Path เป็นเรื่องเลือกได้ (optional) สิ่งที่สำคัญคือคุกกี้ถูกตั้งค่าก่อนส่งบรรทัดเวทย์ "Content-type:text/html\r\n\r\n