• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Quick Cookie question

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Quigsby

Member
Joined
Feb 28, 2004
Location
Fargo, ND
Hey folks, having problem making a cookie recording number of visits to a website.
PHP:
   // cookies.php
   // Program to write a cookie to a client's machine

   extract( $_POST );
   // write each form fields value to a cookie and set the
   // cookies expiration date
   setcookie( "Name", $NAME, time() + 60 * 60 * 24 * 5 );
   setcookie( "Color", $COLOR, time() + 60 * 60 * 24 * 5 );

   extract( $_COOKIE );
   if($_COOKIE[Visits] > 0 ){
   //also tried if(isset($VISITS)){
      $VISITS = $VISITS + 1;
   }
   else{
      $VISITS = 1;
   }
   setcookie( "Visits", $VISITS, time() + 60 * 60 * 24 * 5 );

The $VISITS always remains 1, I can't figure it out. It should go to 1, and then update every time after.
 
Last edited:
You need to set the $VISITS variable.

Try this:

Code:
// cookies.php
   // Program to write a cookie to a client's machine

   extract( $_POST );
   // write each form fields value to a cookie and set the
   // cookies expiration date
   setcookie( "Name", $NAME, time() + 60 * 60 * 24 * 5 );
   setcookie( "Color", $COLOR, time() + 60 * 60 * 24 * 5 );

   $VISITS = $_COOKIE[Visits];  //This is the change.
   extract( $_COOKIE );
   if($_COOKIE[Visits] > 0 ){
   //also tried if(isset($VISITS)){
      $VISITS = $VISITS + 1;
   }
   else{
      $VISITS = 1;
   }
   setcookie( "Visits", $VISITS, time() + 60 * 60 * 24 * 5 );
 
I think the thing most disturbing thing with coding is when there's something very very small and you can't think of it, and when someone points it out you feel stupid.

I can't thank you guys enough. Thanks a million.
 
Back