【发布时间】:2011-09-05 05:38:14
【问题描述】:
我已经在 header.php 中设置了 cookie,如下所示
<?php if($_GET['signup'] == '123' && !isset($_COOKIE['sign'])){
setcookie("sign", "1", time()+3600);
} ?>
现在我需要在页面signup.php 中获取这个cookie 值。但我无法检索该页面中的值。在 Signup.php 页面中,我使用以下代码检查 cookie,
<?php
/**
Template Name: Sign Up
*/
$ck = $_COOKIE['sign'];
echo "cookie".$ck;
if(isset($_COOKIE['sign'])){
header("Location: https://www.ap.com/app/signup.jsp?signup=123");
}
else
{
header("Location: https://www.ap.com/app/signup.jsp");
}
?>
但它只进入 else 条件(如果还设置了 cookie)。好心的建议...
【问题讨论】:
-
您将无法在
header.php中设置 cookie。到那时,为时已晚。见stackoverflow.com/questions/6183162/… -
所以我需要在functions.php中设置cookie对吗?
-
可能。 Wordpress 使得在输出开始之前设置任何标题变得困难(但并非不可能)