【问题标题】:I am not able to set a cookie in php [duplicate]我无法在 php 中设置 cookie [重复]
【发布时间】:2015-09-29 17:01:56
【问题描述】:
  <?php
  $product1 = "user";


  if(!isset($_COOKIE[$cookie_name])) {
  $value=1;
  echo "Cookie named '" . $product1 . "' is not set!";
   setcookie($product1, $value, time() + (86400 * 30), "/");
   } else {
  echo "Cookie '" . $product1 . "' is set!<br>";
  echo "Value is: " . $_COOKIE[$product1];
   $value=$_COOKIE[$product1];
   setcookie($product1, $value, time() + (86400 * 30), "/");
   }
   ?>

// 刷新页面后,我不断收到名为 user is not set 的消息 cookie。请帮忙

【问题讨论】:

  • 我在 if 语句中将 $cookie_name 更改为 $product

标签: php


【解决方案1】:
  $product1 = "user";
//print_r($_COOKIE);

  if(!isset($_COOKIE[$product1])) {
  $value=1;
  echo "Cookie named '" . $product1 . "' is not set!";
   setcookie($product1, $value, time() + (86400 * 30), "/");
   } else {
  echo "Cookie '" . $product1 . "' is set!<br>";
  echo "Value is: " . $_COOKIE[$product1];
   $value=$_COOKIE[$product1];
   setcookie($product1, $value, time() + (86400 * 30), "/");
   }

【讨论】:

  • 它有效,但有什么区别?除了 if 条件中的问题
猜你喜欢
  • 1970-01-01
  • 2013-03-18
  • 2013-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多