douqiju2520 2019-02-07 21:33
浏览 76

通常,PHP cookie名称变量应该保存在自己的变量中

https://secure.php.net/manual/en/function.setcookie.php gives the following example:

<?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);
?>

In general, is this the right way to do it, or when looking at good php code in general would you rather/normally see this:

<?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);
?>

I know this is an open ended question, but I'm new to php and I want to know why you would do it either way. Or is it pure user preference?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 关于#python#的问题:自动化测试