Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

increment cookie value by one each time page is run

Posted on 2013-02-04
2
Medium Priority
?
861 Views
Last Modified: 2013-02-04
<?php

      setcookie('increment_by_1_this_number','1',time()+300000);
            echo '<pre>';
      print_r($_COOKIE);
      echo '</pre>';

Open in new window



I want to increment by 1 the cookie value if cookie is set
0
Comment
Question by:rgb192
2 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 2000 total points
ID: 38852205
<?php

    if (!isset($_COOKIE['increment_by_1_this_number'])) $_COOKIE['increment_by_1_this_number'] = 0;
    $visits = $_COOKIE['increment_by_1_this_number'] + 1;
    setcookie('increment_by_1_this_number',$visits,time()+300000);

    echo '<pre>';
    print_r($_COOKIE);
    echo '</pre>';

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 38852502
thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question