473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Help with cookies

24
Every time when I run my code the result is 1 time. I do not understand why? I imagine that the time should be grow. It should be 1 time, 2 time and so on.
My code is:

<?
$counter=0;
$counter++;
setcookie('counter',$counter);
if(isset($_COOKIE['counter']))
$counter1=$_COOKIE['counter'];
echo $counter1."<br>";
echo "Last visit $counter1 times";
?>
Jan 14 '08 #1
1 1063
MarkoKlacar
296 Expert 100+
Every time when I run my code the result is 1 time. I do not understand why? I imagine that the time should be grow. It should be 1 time, 2 time and so on.
My code is:

<?
$counter=0;
$counter++;
setcookie('counter',$counter);
if(isset($_COOKIE['counter']))
$counter1=$_COOKIE['counter'];
echo $counter1."<br>";
echo "Last visit $counter1 times";
?>
Hi,

Well since your $counter variable is being re-set every time the user visits the site the fact that it always displays '1' is not that strange.

What you should do is check whether the cookie is set or not before you assing $counter a value.

if(isset($_COOKIE['counter'])){
// your code for outputting the value of $counter
}
else{
// create variable $counter and setting the cookie
}

Hope you get it in order.

Cheers
Jan 15 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: collie | last post by:
Hi, I have an asp page that needs to create 2 different cookies: one for the admin and one for the user. The code that I have to work with was created by someone else. the page first requires to...
18
by: | last post by:
Please help. After a number of wrong turns and experiments I need advice on login management system to secure our web pages without inconveniencing our visitors or our internal staff. What I...
0
by: Bennett F. Dill | last post by:
Thanks for reading. I'm having problems with cookies from asp to asp.net and back! It seems like I can set a cookie in asp.net fine, and alter it at will, as soon as asp touches it, asp.net...
3
by: Calvin KD | last post by:
Hi everyone, Can someone tell me what's wrong with the way that i read a cookie as below: private void Page_Load(object sender, System.EventArgs e) { Response.Cookies.Clear(); HttpCookie...
4
by: serge calderara | last post by:
Dear all, I try to make some test on how to use basic cookie but get some trouble in the sens that I was not able to read back previous cretaed cookies. In page_load event I have the following...
0
by: Alan Silver | last post by:
Hello, I am having a problem setting and resetting cookies. I'm sure I just doing something really stupid as this is such a basic issue, but I can find any answer. Please can someone help me? ...
3
by: Phillip N Rounds | last post by:
I'm having trouble with using cookies to monitor the stages of login. I have a two stage Registration page ( register.aspx ) and my target page ( MyPage.aspx ) I'm using a cookie named LoginStatus...
7
by: isaac2004 | last post by:
hi i have a basic asp page that acts as an online bookstore. on my cart page i am having trouble generating 3 numbers; a subtotal, a shipping total, and a final price. here is my code i would...
2
by: isaac2004 | last post by:
hi i am creating a basic asp site that uses cookies to manage a cart for an online store. whenever i open this page without adding anything to the cart. i get an error message. here is my code ...
6
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.