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
3 Answers
Reset to default 5i 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
版权声明:本文标题:set cookie value in javascript and displaying it with php - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741317911a2372029.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论