首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP - setcookie

PHP - setcookie
EN

Stack Overflow用户
提问于 2018-08-31 17:56:11
回答 2查看 76关注 0票数 1

我有一个插件,在我的主类中是:

代码语言:javascript
复制
function test_handle_post(){
    //code
    add_action( 'init', 'add_Cookie' );
}


function add_Cookie() {
    $productname = get_name();
    $filename = $_FILES['upload_file']['name'];
    setcookie('jeden','dwa');
}


function get_name( $context = 'view' ) {
    return $this->get_prop( 'name', $context );
}

并且setcookie()不起作用,因为它没有添加cookie。为什么?请帮帮我。我用这些问题搜索了很多页面,但一无所获。

EN

回答 2

Stack Overflow用户

发布于 2018-08-31 18:03:02

试试这个

代码语言:javascript
复制
setcookie("jeden", "dwa", time()+3600) or die('unable to create cookie');
票数 1
EN

Stack Overflow用户

发布于 2018-08-31 18:41:01

代码语言:javascript
复制
Setcookie will set persistent cookie with following syntax -

setcookie(name,value,expire,path,domain,secure,httponly);
// here name  is only the mandatory all remainings are optional
// now you did not specify the value of expires parameter and 
// by default it's value is 0 means the cookie will expire at the end of the session (when the browser closes)

// following code set cookie for 30 days (60*60*24 = 86400 seconds in a day) and path is current url
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52112922

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档