Solved

PHP & Cookies

Posted on 2007-04-10
3
366 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now