admin管理员组

文章数量:1287629

i am having an output problem and i can't seem to trace the problem, here is the code:

sample.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;

output.php

<?php echo implode($_COOKIE)?>

and it displays

713qnihjmdt7mdq8eejvlcd1q1

but i want to display the date stored in the tempo variable,

i tried dispaying the tempo variabe directly and it dispalyed the right output,

any suggestions? i think i need to add a code in the php side.

i am having an output problem and i can't seem to trace the problem, here is the code:

sample.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;

output.php

<?php echo implode($_COOKIE)?>

and it displays

713qnihjmdt7mdq8eejvlcd1q1

but i want to display the date stored in the tempo variable,

i tried dispaying the tempo variabe directly and it dispalyed the right output,

any suggestions? i think i need to add a code in the php side.

Share Improve this question edited Sep 12, 2012 at 5:18 Patrick Narcelles asked Sep 12, 2012 at 5:11 Patrick NarcellesPatrick Narcelles 1672 gold badges3 silver badges12 bronze badges 1
  • 1 Related: stackoverflow./questions/5045053/… – jedwards Commented Sep 12, 2012 at 5:22
Add a ment  | 

3 Answers 3

Reset to default 5

i just changed the following

document.cookie='fcookie='+tempo; 

and

if (isset($_COOKIE["fcookie"])) 
echo $_COOKIE["fcookie"]; 
else 
echo "Cookie Not Set";

Your script has couple of mistakes, I have modified them and added some extra codes, Hope this works for you

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

More about Javscript cookies and Php Cookies

First of all, the $_COOKIE you are seeing is the PHPSESSID cookie... You are not viewing the JS cookies. This article has good info on the relationship between PHP and JS cookies: http://www.quirksmode/js/cookies.html

本文标签: set cookie value in javascript and displaying it with phpStack Overflow