简体   繁体   English

如何从 header 获取 cookie 值到 wordpress 中的模板页面?

[英]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.

相关问题 Wordpress - 如何编辑模板的标题? - Wordpress - How can I edit the header of a template? 如何从页面正文中的自定义字段获取值,然后将其放在标题的meta标签内容中? WordPress的 - How can I get value from a custom field in body of a page, then put it in the meta tags content in header? Wordpress 如何在Wordpress的不同页面上使用一个模板? - How can i use one template on different pages in wordpress? 我如何在Laravel中获得Cookie的价值 - How can i get cookie value in laravel 如何使用Javascript / jQuery在Wordpress主题模板上设置cookie,然后在另一个模板中显示cookie值(如果是isset) - How do I set a cookie on a Wordpress theme template using Javascript/jQuery and then display the cookie value in a different template (if isset) 我如何从响应 header 中获取价值 | API | CURL - how can i get value from response header | API | CURL 如何从 Wordpress 插件模板获取变量到 Wordpress 主题 header.ZE1BFD762321E4099634AC0B6E841 - How to Get Variable from Wordpress Plugin Template to Wordpress theme header.php 如何从特定的wordpress页面上删除所有侧边栏? - How Can i Remove all sidebars from specific wordpress pages? 无法使用特定模板获取Wordpress页面列表 - Can't get list of wordpress pages using specific template 从 HTTP 获取 Cookie 值 GET 请求 Header 字符串 - Get Cookie Value From HTTP GET Request Header String
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM