Reading My Cookie

Links for php scripts

Moderators: macek, egami, gesf

Halocaust
New php-forum User
New php-forum User
Posts: 6
Joined: Thu Mar 03, 2005 3:17 pm
Location: Huntington, WV
Contact:

Reading My Cookie

Postby Halocaust » Sat Mar 26, 2005 3:57 pm

Ok Less Green then before...

Ok here is my problem. I need to be able to read the data out of my cookie that I made and be able to display it in my shopping cart, after that I am good to go...here is my entire code for my cookie maker.

Code: Select all

<?php
If (! isset($_GET["Status"]))
    $Status = 0;
Else
    $Status = $_GET["Status"];
      
Switch ($Status) {
   Case 0:
      Break;
   Case 1:
      //Make a Cookie
         $ID = $_GET['ID'];
      if (!isset($_COOKIE["$ID"])) {
         setcookie("$ID", 1, time()+604800);
                          }
      else
       {
         setcookie("$ID", ++$_COOKIE["$ID"], time()+604800);
      }
         Break;
      }
?>


This might look like crap, just cut and pasted it from my code. the $ID variable is my actual ProdID when the user clicks the "Add" button of my products.
I have switching setup as status 0= you are just browsing the site, and status 1=you have just clicked the "Add" button associated with my product and you have made a cookie or have updated the qty within it after you have clicked the continue shopping link I have which resets your status to 0, etc...

User avatar
Alexej Kubarev
Site Admin
Site Admin
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län
Contact:

Postby Alexej Kubarev » Sun Mar 27, 2005 2:12 am

use $_COOKIE[$ID] for that -- that varialbe contains the information that you have in your cookie..

Halocaust
New php-forum User
New php-forum User
Posts: 6
Joined: Thu Mar 03, 2005 3:17 pm
Location: Huntington, WV
Contact:

Postby Halocaust » Sun Mar 27, 2005 9:03 am

Ok worked great....but only after I clicked the continue shopping link and added the same products did it actually display the amount. So, only affter the product qty became 2 in the cookie would it display the value to the customer that is shopping.

Any suggestions on how to display the single value...

Also this is my echo statement any suggestions on how to display all the content in the cookie? Say if I click continue shopping and add diifferent product...its in the same cookie but only the new value is showing and the amount after the qty is 2.



Code: Select all

Case 1:
         if (isset($_GET["ID"]))   
         {
         //This is the Big Golden Goose of Shopping Cart Data
            $ID = $_GET["ID"];
            $Price = $_GET["price"];
            $Cat = $_GET["CatID"];
               echo "<H2> Hello Golden Goose</h2>";
               echo "<p> Your Selected ID was: $ID  Your Selected Price was: $$Price </p>";
               echo "<a href=\"". $PHP_SELF . "?Status=0&CatID=" . $Cat . "\">Continue Shopping</a>";
               echo "<br>";
               echo "Number of $ID Items in Your Cart are: This is where the 'Cookie Name Should Be' $_COOKIE[$ID]";
               }
         break;
         }
         ?>


This is the 2nd part of the code when the Status = 1, first this actually happens then the cookie gets make which is the first posted code, then this is where the variable actions happen and the data gets put into the variables to be stored in the cookie and redisplayed.


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest

cron