cookies - Outputting getcookie variable in PHP without browser refresh -


i using following code output block of content without cookie, , number if cookie has been set. problem getcookie variable doesn't work until page has been refreshed, or user navigates next page.

i happy use header redirect not sure put within code (unless has better solution code itself):

if (is_page(817)) {     setcookie("phonecookie", 1, time()+3600, cookiepath, cookie_domain); } if ($_cookie["phonecookie"] =="") {     echo "no cookie here"; } else {      echo "cookie stored!";  } 

also, code above sets cookie if visitor lands on specific page within wordpress.

is there way via query string e.g. example.com/?src=affiliate

try this

if ((is_page(817) && (!isset($_cookie["phonecookie"]) {      setcookie("phonecookie", 1, time()+3600, cookiepath, cookie_domain);       //your redirect code here      header("location:yoururl); } elseif (isset($_cookie["phonecookie"])) {      echo "cookie stored!";   } else {      echo "no cookie here or page not 817"; } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -