I want to set a cookie, if a user visits Page "Test-2". When the cookie is set and the visitor tries to visit Page "Test" within 24 hours he should be automatically redirected to Page "Test-2".
Here is the Code I inserted to the function.php file of my Wordpress Theme:
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;
}
}
However now I've the following error: "Parse error: syntax error, unexpected 'dz_offer' (T_STRING)"
Any ideas how to fix this and get it working?
Thanks for your help!
+++ UPDATE +++
The Error is gone now. However the cookie isn't stored, when I visit page "test-2"
Here is the updated Code I'm using:
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;
}
}