Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在HTML中打印cookie值?_Javascript_Php_Html - Fatal编程技术网

Javascript 如何在HTML中打印cookie值?

Javascript 如何在HTML中打印cookie值?,javascript,php,html,Javascript,Php,Html,我正在一个数字猜测网站上工作。网站概况如下所示: 在setCookiesA.php中,有两个名为ccolor和maxNum的cookie存储的最大猜测数。存储cookie后,播放器将重定向到gussinga.php。代码如下所示: <?php setCookie("c",$_GET["itemChosen"],time()+(86400 * 365), "/"); setCookie("maxNo",$_GET["noGuess"],time()+(86400 * 365

我正在一个数字猜测网站上工作。网站概况如下所示:

在setCookiesA.php中,有两个名为ccolor和maxNum的cookie存储的最大猜测数。存储cookie后,播放器将重定向到gussinga.php。代码如下所示:

<?php
    setCookie("c",$_GET["itemChosen"],time()+(86400 * 365), "/");
    setCookie("maxNo",$_GET["noGuess"],time()+(86400 * 365), "/");
    header("Location:GuessingA.php");
?>
如何获取cookie值?多谢各位

你只是在写文本。这里没有PHP代码

看看你在这里做了什么:

那样做

<p> You have chosen the <?php print htmlspecialchars($_COOKIE['c']); ?> channel for  guessing</p>

我的意思是它是如此的基本和容易找到。。。为什么直接来这里而不是搜索,谷歌;你没有设置c变量,除非它在更高的范围内,并且你没有显示你应该在我的程序中显示它,有两个cookies存储,color和maxNum。因此,我想知道我是否只能得到颜色。
function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }
function change()
    {
        var color=readCookie(c);
        color.innerHTML="You have chosen the " +color+" channel for  guessing";
    }
<p> You have chosen the $_COOKIE[c] channel for  guessing</p>
 <form method="post" action="<?php print htmlspecialchars($_SERVER['PHP_SELF'])?>">
<p> You have chosen the <?php print htmlspecialchars($_COOKIE['c']); ?> channel for  guessing</p>