PHP-setcookie

PHP-setcookie,php,wordpress,cookies,Php,Wordpress,Cookies,我有一个插件,我的主要类是: 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_n

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

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。 为什么?请帮帮我。我已经搜索了这么多有这些问题的页面,但什么都没有。

试试这一个

setcookie("jeden", "dwa", time()+3600) or die('unable to create cookie');

获取cookie的代码在哪里?有错误吗?如何执行此代码?您如何确保未创建cookie?您的输入是什么?你的预期产出是多少?实际产量是多少?生成了什么错误日志消息?你试过的代码是什么?这是一个好问题。所以,我的代码在主类中。文件夹(插件)主类我有上传文件,我想保存路径和产品(woocommerce)——所以我使用setcookie来保存这个。但我没有得到任何错误,只是没有保存。这是我的代码:(我不发布这个插件)当我使用code@Bhargav Chudasama我的产品时,添加文件后它不会显示。我不知道还有什么要解释的。如果你对你的问题有任何进一步的问题,请告诉我。如果您认为这是正确答案,请接受为正确答案。幸运的是,类似的情况会发生:代码:
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), "/");