Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

Search Help:  
 
Enter keywords to search help.

How do I set and read cookies?

You can set cookies by using the setcookie($name, $value) function. Reading cookies in PHP is extremely easy — just refer to them by name.

To keep track of how many times someone accesses your site, for example, try this code:

$MyCookieName = "visits";
if (!$visits) {
$visits = 0;
}
$visits = $visits + 1;
setcookie($MyCookieName, $visits);

To learn more about PHP, we suggest consulting the PHP Group web site or other PHP resources.

Was this article helpful?

Yes   No
Click to contact Customer Care for further assistance.