Solved

increment cookie value by one each time page is run

Posted on 2013-02-04
2
705 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 500 total points
Comment Utility
<?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
Comment Utility
thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now