我有插件,在我的主要课程中是这样的:
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');
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), "/");