PHP Cookie无法处理重定向

PHP Cookie无法处理重定向,php,forms,cookies,Php,Forms,Cookies,我有一个相当令人沮丧的问题。我正在尝试将表单变量存储到cookie中 <form id = "vraagStellen" action = "shoutbox.php" method = "post" class = "col-lg-4 col-md-6 col-sm-12" role="form"> <a name = "bottomOfPage"></a> <div class = "selectAfbeelding form-gro

我有一个相当令人沮丧的问题。我正在尝试将表单变量存储到cookie中

<form id = "vraagStellen" action = "shoutbox.php" method = "post" class = "col-lg-4 col-md-6 col-sm-12" role="form">
    <a name = "bottomOfPage"></a>
    <div class = "selectAfbeelding form-group">
        <label for "gamertag">Gamertag:</label>
        <input type = "text" id = "gamertag" name = "gamertag" class = "form-control" maxlength="30" value="<?php if(isset($_COOKIE['gamertag'])){echo $_COOKIE['gamertag'];} else {echo "";} ?>" placeholder="<?php if(isset($_COOKIE['gamertag'])){echo $_COOKIE['gamertag'];} else {echo "Hier typen";} ?>" required>
    </div>
    <div class = "selectVraag form-group">
        <label for "bericht">Bericht:</label>
        <textarea id = "bericht" onkeyup = "count()" name = "bericht" class = "form-control" maxlength="100" cols = "40" rows = "2" placeholder = "Hier typen" required></textarea>
        <div id = "countDiv"></div>
    </div>
    <div class = "form-group">
        <input type="submit" name = "verzend" value = "Verzenden" id = "verzenden">
        <input type="reset" name = "reset" value = "Leegmaken" id = "reset"> 
    </div>
</form> 

玩家代号:

确保$\u SERVER['SERVER\u NAME']中的值正好是link.nl,而不是www.link.nl。对于浏览器,这是两个不同的值,因此它们创建了两个不同的cookie。

可能您使用了无效的会话id或
PHPSESSID
。你能检查一下PHPSESSID吗

if (isset($_POST['gamertag']) && isset($_POST['bericht']) && !empty($_POST['gamertag']) && !empty($_POST['bericht'])){

$afbeelding_before = $_POST['gamertag'];
$vraag_before = $_POST['bericht'];

$cookie_var = $_POST['gamertag'];

$afbeelding = mysql_real_escape_string($afbeelding_before);
$vraag = mysql_real_escape_string($vraag_before);

setcookie("gamertag", $cookie_var, time() + (86400 * 30), "/",$_SERVER['SERVER_NAME']);

//echo $afbeelding . $vraag;

$sql3="INSERT INTO `shoutbox` (`id`, `gamertag`, `bericht`, `date`) VALUES (NULL, '$afbeelding', '$vraag', CURRENT_TIMESTAMP)";
mysql_query($sql3,$con);

echo "post gamertag ".$_POST['gamertag']."<BR>";
echo "cookie ". $_COOKIE['gamertag']."<BR>";

header('Location: http://link.nl#shoutbox');

}

else{
    echo 'Er ging iets fout...';
}