PHP - setcookie - PullRequest
       15

PHP - setcookie

0 голосов
/ 31 августа 2018

У меня есть плагин, и в моем основном классе это:

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 () не работает, потому что не добавляет куки. Зачем? Пожалуйста, помогите мне. Я искал так много страниц с этими проблемами и ничего.

Ответы [ 2 ]

0 голосов
/ 31 августа 2018
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 голосов
/ 31 августа 2018

попробуй с этим

setcookie("jeden", "dwa", time()+3600) or die('unable to create cookie');
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...