?
Solved

PHP & Cookies

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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…
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.
Suggested Courses

777 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