我通过JavaScript创建了一个cookie,我是否也可以在PHP中访问它?
JS创建一个cookie
function pb_create_cookie(name, value, days2expire, path) {
var date = new Date();
date.setTime(date.getTime() + (days2expire * 24 * 60 * 60 * 1000));
var expires = date.toUTCString();
document.cookie = name + '=' + value + ';' +
'expires=' + expires + ';' +
'path=' + path + ';';
}
pb_create_cookie('tour_in_progress', '1', 30, "/");
pb_create_cookie('tour_id', 105, 30, "/");
pb_create_cookie('tour_step', 0, 30, "/");
PHP中的Cookie使用
$tour_id = $_COOKIE['tour_id'];
$tour_progress = $_COOKIE['tour_in_progress'];
$tour_step = $_COOKIE['tour_step'];
参考:http://www.pontikis.net/blog/create-cookies-php-javascript