Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP & Cookies

Posted on 2007-04-10
3
Medium Priority
?
412 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

610 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