• I am trying to set a cookie only when someone goes to a particular page. So that after that the user will always be directed to that page even if they type in the homepage (the home page is only a squeeze page where they sign up)

    I am using the headway them an have been having a real problem trying to get this to work.

    I am note sure where to place the code because, setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script this is a protocol restriction. This requires that you place calls to this function prior to any output,including <html> and <head> tags as well as any whitespace.

    I am a real noob at this so sorry if I am being unclear.

    <?php
    if ( is_page( 8 ))
          setcookie("reg_user", time()+60*60*24*365);
    
    if (isset ($_COOKIE['reg_user']))
      header ("Location: https://surveygroupie.com");
    else
      header ("Location: https://surveygroupie.com/member-area");
    ?>

    Thanks for the help.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Set PHP Cookies and redirect’ is closed to new replies.