www.webdeveloper.com
Results 1 to 3 of 3

Thread: How do you read variables from cookie?

  1. #1
    Join Date
    May 2006
    Posts
    138

    How do you read variables from cookie?

    PHP Code:

    //Sets Cookie

    setcookie("UWGFH[fn]"'John'time()+60*60*24*30,"/",".mydomain.com");
    setcookie("UWGFH[ln]"'Doe'time()+60*60*24*30,"/",".mydomain.com");
    setcookie("UWGFH[cm]"'Fake Company'time()+60*60*24*30,"/",".mydomain.com");
    setcookie("UWGFH[pac]"'915'time()+60*60*24*30,"/",".mydomain.com");
    setcookie("UWGFH[ppf]"'415'time()+60*60*24*30,"/",".mydomain.com");
    setcookie("UWGFH[psf]"'5555'time()+60*60*24*30,"/",".mydomain.com");
    setcookie("UWGFH[ea]"'blank@aol.com'time()+60*60*24*30,"/",".mydomain.com"); 
    PHP Code:

    //Read Cookie??

    if(isset($_COOKIE['UWGFH'])) {

    echo 
    "Hello $fn $ln, you work at $cm. Your phone number is ($pac)-$pff-$psf. We can reach you also via email at $ea.";
     
    }

    How do I get the data from the cookie and store them in their own variable

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,326
    PHP Code:
    echo "Hello {$_COOKIE['UWGFH']['fn']} {$_COOKIE['UWGFH']['ln']} ...rest of string..."
    A suggestion to save some HTTP traffic:
    PHP Code:
    // set one cookie:
    setcookie('UWGFH''John,Doe,Fake Company,915,415,5555,blank@aol.com'time()+60*60*24*30,"/",".mydomain.com");

    // read and explode the cookie:
    list($fn$ln$cm$pac$ppf$psf$ea) = explode(','$_COOKIE['UWGFH']);
    echo 
    "Hello $fn $ln, you work at $cm. Your phone number is ($pac)-$pff-$psf. We can reach you also via email at $ea."
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    May 2006
    Posts
    138
    Thanks NogDog, that was actually my second question, how do I combine all the variables under just one "setcookie", this is scary, stop reading my mind. I didn't give you permission! *laugh*

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles