Programming Basics
  Home arrow Programming Basics arrow Page 2 - 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 - Basic Cookie


    (Page 2 of 4 )

    Let's look at an example that uses a very basic cookie:

    <?php
    if (!isset($_COOKIE["name"])) {

      
    setcookie("name"$_POST["name"]);
      
    setcookie("visits"1);

      echo 
    "Hello $_POST[name]. &lt;br /&gt;";
      echo 
    "It appears that this is your first visit!";

    } else {
      
    setcookie("visits", ++$_COOKIE["visits"]);

      echo 
    "Welcome back, $_COOKIE[name]. &lt;br /&gt;";
      echo 
    "You have visited us $_COOKIE[visits] times!";
    }
    ?>

    The two points of interest are $_COOKIE and setcookie.

    Cookie information sent by the browser is accessed with $_COOKIE, a super global array containing cookie values keyed by name.

    The setcookie function is used to assign a key/value pair to be sent back to the client. The client uses the new values to update its cookies if the information already exists. If the information doesn't exist, new cookies will be created.

    Remember that cookie information is exchanged within HTTP headers; cookies must be sent before the script generates any output.

    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 3 hosted by Hostway