I just copy and pasted set cookie sample code(http://www.w3schools.com/php/php_cookies.asp) to my module and tpl.php
In my module, I put the setcookie in my submit function as below:
function custom_request_price_form_submit($form,&$form_state){
$cookie_name = "user";
$cookie_value = "John Doe";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
if(!isset($_COOKIE[$cookie_name])) {
drupal_set_message("Cookie named '" . $cookie_name . "' is not set!");
} else {
drupal_set_message("Cookie '" . $cookie_name . "' is set!<br>");
drupal_set_message("Value is: " . $_COOKIE[$cookie_name]);
}
}
Im my node--XXX.tpl.php, I just copy the code without modification as below:
$cookie_name = "user";
$cookie_value = "John Doe";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_name];
}
However, no matter how I refresh the webpage, the message always shows "Cookie named 'user' is not set!"
I also tried user_cookie_save function, but no luck. Does anyone know why my cookie setting doesn't work?