1

我有一个输出问题,我似乎无法追踪问题,这里是代码:

示例.js

var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var cmonth = myDate.getMonth();
var cdate = myDate.getDate();
var temp1 = m_names[cmonth];
var tempo = escape(temp1 + " " + cdate);
document.cookie=fcookie"=" + tempo;

输出.php

<?php echo implode($_COOKIE)?>

它显示

713qnihjmdt7mdq8eejvlcd1q1

但我想显示存储在 tempo 变量中的日期,

我尝试直接显示速度变量,它显示了正确的输出,

有什么建议么?我想我需要在 php 端添加一个代码。

4

3 回答 3

5

我刚刚更改了以下内容

document.cookie='fcookie='+tempo; 

if (isset($_COOKIE["fcookie"])) 
echo $_COOKIE["fcookie"]; 
else 
echo "Cookie Not Set";
于 2012-09-12T06:00:57.323 回答
3

你的脚本有几个错误,我已经修改了它们并添加了一些额外的代码,希望这对你有用

<script>
    fcookie='mycookie';
    var monthname = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    var myDate=new Date();//--->getting today's date
    var cmonth = myDate.getMonth();
    var cdate = myDate.getDate();
    var temp1 = monthname[cmonth];
    var tempo = escape(temp1 + " " + cdate); 
    document.cookie=fcookie+"=" + tempo;//-->missing cookie name and concatenation
    </script>
    <?php
    if (isset($_COOKIE["mycookie"]))
      echo $_COOKIE["mycookie"];
    else
       echo "Cookie Not Set";
    ?>

有关Javscript cookiePhp Cookie的更多信息

于 2012-09-12T05:25:04.867 回答
1

首先,您看到的 $_COOKIE 是 PHPSESSID cookie...您没有查看 JS cookie。这篇文章很好地了解了 PHP 和 JS cookie 之间的关系:http ://www.quirksmode.org/js/cookies.html

于 2012-09-12T05:18:09.407 回答