https://secure.php.net/manual/en/function.setcookie.php 给出以下示例:
<?php
$value = 'something from somewhere';
setcookie("TestCookie", $value);
setcookie("TestCookie", $value, time()+3600); /* expire in 1 hour */
setcookie("TestCookie", $value, time()+3600, "/~rasmus/", "example.com", 1);
?>
通常,这是正确的方法吗?或者,通常在查看良好的php代码时,您宁愿/通常会看到以下内容:
<?php
$value = 'something from somewhere';
$cookie_name = 'TestCookie';
setcookie($cookie_name, $value);
setcookie($cookie_name, $value, time()+3600); /* expire in 1 hour */
setcookie($cookie_name, $value, time()+3600, "/~rasmus/", "example.com", 1);
?>
我知道这是一个开放式的问题,但是我是php的新手,我想知道为什么您会选择这两种方式。还是纯粹的用户偏好?