[英]How can i get the cookie value from header to template pages in wordpress?
I have set the cookie in header.php like below我已经在 header.php 中设置了 cookie,如下所示
<?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.现在我需要在页面 signup.php 中获取这个 cookie 值。 but i cant retrive the value in that page.
但我无法检索该页面中的值。 in Signup.php page i am using the below code for check the 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");
}
?>
but it goes to the else condition only (if the cookie is set also).但它只进入 else 条件(如果还设置了 cookie)。 kindly advice...
好心劝告...
Try to create a plugin and hook with init action: http://codex.wordpress.org/Plugin_API/Action_Reference/init尝试使用 init 操作创建一个插件和挂钩: http://codex.wordpress.org/Plugin_API/Action_Reference/init
function my_set_cookie() {
if($_GET['signup'] == '123' && !isset($_COOKIE['sign'])) {
setcookie("sign", "1", time()+3600);
}
}
add_action('init', 'my_set_cookie');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.