Solved

PHP & Cookies

Posted on 2007-04-10
3
386 Views
Last Modified: 2010-05-18
Hi,

In the PHP manual there is a sample code of cookies :

"or a shopping cart application you may want to keep a counter and pass this along. i.e."
<?php
if (isset($_COOKIE['count'])) {
    $count = $_COOKIE['count'] + 1;
} else {
    $count = 1;
}
setcookie('count', $count, time()+3600);
setcookie("Cart[$count]", $item, time()+3600);
?>


I am not familiar with cookies and never used them,
could someone explain me why one would store the items of a customer into cookies ?
What could this example be used for ?

Thank u.
0
Comment
Question by:matthew016
3 Comments
 
LVL 27

Accepted Solution

by:
yodercm earned 500 total points
ID: 18881967
Cookies are small, retrievable files stored on the user's computer (provided the user allows cookies in his security settings).  They allow web applications to save information for each user, so the user doesn't have to enter it each time s/he uses your website.  

It is commonly used for logins, for last-access information, or the like.
0
 
LVL 48

Expert Comment

by:hernst42
ID: 18882036
As told cookies are stored client sied. So a user can be recognized based upon the stored cookie for autologin or formular data can be stored so the formfields are prefilled based on the last input of the user. So cookies can make the life for the user a little bit convienend. On the other side cookies are also often used to track the user between different sides which use the same tracking/advertising service.
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 18882426
What is worth mentioning is that cookies and data from cookies should not be "trusted", and you should be aware that data in cookies is stored on client side and therefor might be subject to manipulation by hackers/crackers/adware etc.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

856 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