$value = "Hello world!";
// cookie will expire when the browser closes
setcookie("myCookie", $value);
// cookie will expire in 1 hour
setcookie("myCookie", $value, time()+3600);
// cookie will expire in 1 hour, and will only be available
// within the php directory + all sub-directories of php
setcookie("myCookie", $value, time()+3600, "/php/");
<html>
<body>
</body>
<!-- Mirrored from www.w3schools.com/php/phptryit.asp?filename=tryphp_func_http_setcookie2 by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 02:51:05 GMT -->
</html>