This is much simpler to do than the JavaScript method. Use the setcookie() function. The cookie can, after the next page load, be read via the $_COOKIES variable.
Setting cookies can be tricky, be sure to specify at least a path of the optional parameters, or your cookies will not work in some older browsers.