Here is a basic example
<? setcookie("foobar", "Hello, world!", -1) ?>
This will create a cookie named "foobar" with the value of "Hello, world!", and will expire when the browser closes.
Also, make sure you set cookies before any HTML output otherwise it won't be created.
To check it's value, do on a following page.
<? echo $_COOKIE['foobar']; ?>