Programming Basics
  Home arrow Programming Basics arrow Page 3 - Cookies in PHP
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PROGRAMMING BASICS

Cookies in PHP
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 27
    2004-01-27

    Table of Contents:
  • Cookies in PHP
  • Basic Cookie
  • Cookie Attributes
  • Words Of Caution

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Cookies in PHP - Cookie Attributes


    (Page 3 of 4 )

    I mentioned earlier that cookies can also be assigned several attributes: an expiration date, a valid domain, a valid domain path and an optional security flag.

    The expiration time is used by the browser to determine when the cookie should be deleted. It is expressed as a Unix timestamp plus the number of seconds before the cookie expires.

    The valid domain is a partial or complete domain name to which the cookie will be sent. For example, if the value for the valid domain attribute is "www.example.net", the client will send the cookie information every time the user visits the www.example.net subdomain. For the cookie to be accessible within all subdomains of example.net (such as www.example.net, mail.exaple.net, news.example.net, users.example.net, etc.), a leading dot should be used as in ".example.net".

    The path attribute is used to identify sites within various paths in the same domain. For example, cookies with a path attribute of "/" will be both accessible to users.example.net/~tom and users.example.net/~sally. However, a cookie with a path attribute of "/~tom" will only be made available to users.example.net/~tom, not users.example.net/~sally.

    The security flag attribute restricts a browser from sending cookie information over unsecured connections. The default value is 0 and allows the cookie to be sent over any type of HTTP connection. It may be set to 1 which will only permit the cookie to be sent over a secure HTTP (HTTPS) connection.

    The setcookie function accepts not only a key/value pair, but also any of the attributes mentioned above. The syntax for setcookie is setcookie(name, value, [[expiration], [path], [domain], [security]]).

    setcookie("favoriteColor", "blue", time() + 60 * 60 * 24 * 30, "/~tom", "users.example.com", 1); will generate a cookie storing "blue" as $_COOKIE["favoriteColor"]. The cookie will expire after 30 days, and should be made available only if a secure connection has been established to https://users.example.com/~tom.

    More Programming Basics Articles
    More By bluephoenix


       · cool :)
       · Liked your tutorial but really could have used a full blown html page to...
       · I'm glad to hear you've managed to figure out what I ment. I'm sorry I wasn't more...
       · I am already very confident with PHP.Although I still love reading over some basic...
       · It wasn't quite whatI was looking for but has already proved useful thank you.
       · I am soo please with your tutorial and now I am much confident to use cookies in my...
     

    PROGRAMMING BASICS ARTICLES

    - Loops and PHP Decision Making
    - Operators, Conditionals, and PHP Decision-Ma...
    - PHP Decision-Making
    - Coding
    - Server Statistics
    - Looping in PHP
    - Cookies in PHP
    - Working with text files
    - Beginning Object Oriented Programming in PHP
    - A Tour of Decision Making Structures in PHP
    - PHP Strings Primer
    - PHP Control Structures
    - Intro to Vim
    - Reading Directorys with PHP
    - An Overview of Arrays in PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway