如果用户访问页面"Test-2“,我想设置一个cookie。当cookie被设置并且访问者试图在24小时内访问页面"Test“时,他应该被自动重定向到Page "Test-2”。
下面是插入到Wordpress主题的function.php文件中的代码:
if( is_page('test-2’)){
if(isset($_COOKIE['dz_offer'])){
$cookie = $_COOKIE['dz_offer'];
}
else{
setcookie('dz_offer', time() + 60*60*24, '/');
}
}
if( is_page('test‘)){
if (isset($_COOKIE['dz_offer‘])){
header(„Location: https://esample.com/test-2“);
exit;
}
}然而,现在我有了以下错误:“分析错误:语法错误,意外的'dz_offer‘(T_STRING)”
有什么办法解决这个问题并让它发挥作用吗?
谢谢你的帮忙!
+++更新+++
错误现在消失了。但是,当我访问页面"test-2“时,cookie并没有被存储。
下面是我正在使用的更新代码:
if( is_page('test-2')){
if(isset($_COOKIE['dz_offer'])){
$cookie = $_COOKIE['dz_offer'];
}
else{
setcookie('dz_offer',$val, time() + 60*60*24, '/');
}
}
if( is_page('test')){
if (isset($_COOKIE['dz_offer'])){
header("Location: https://example.com/test-2");
exit;
}
}发布于 2016-08-13 10:30:48
有很多错误。无论你在哪里放一个‘而不是’
if( is_page('test-2')){
if(isset($_COOKIE['dz_offer'])){
$cookie = $_COOKIE['dz_offer'];
}
else{
//cookies should be changed in the following way and $val is the value you have to save in the cookie 'dz_offer'.
setcookie('dz_offer',$val, time() + 60*60*24);
}
}
if( is_page('test')){
if (isset($_COOKIE['dz_offer'])){
header("Location: https://esample.com/test-2");
exit;
}
}https://stackoverflow.com/questions/38931732
复制相似问题