Solved

PHP & Cookies

Posted on 2007-04-10
3
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Accepted Solution

by:
Cornelia Yoder 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
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.

707 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