如何在 WordPress 中从标头到模板页面获取 cookie 值?
我已经在 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)。好心的建议...
I have set the cookie in header.php like below
<?php if($_GET['signup'] == '123' && !isset($_COOKIE['sign'])){
setcookie("sign", "1", time()+3600);
} ?>
now i need to get this cookie value in the page signup.php. but i cant retrive the value in that page. in Signup.php page i am using the below code for check the 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");
}
?>
but it goes to the else condition only (if the cookie is set also). kindly advice...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试创建一个插件并与 init 操作挂钩: http://codex.wordpress.org/Plugin_API/ Action_Reference/init
Try to create a plugin and hook with init action: http://codex.wordpress.org/Plugin_API/Action_Reference/init