Answers.Body: <p>Try this:</p>
  
  <pre><code>{% if currentUser %}
      {% set name = currentUser.firstName %}
      {% if craft.lj_cookies.get('account') != name %}
          {% do craft.lj_cookies.set('account', name) %}
          {% redirect name %}
      {% endif %}
  {% endif %}
  </code></pre>
  
  <p>In you're original code you're setting the cookie before getting it into the redirect variable, so the {% if redirect == name %} conditional is always true.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-25T19:50:28.130Z
Answers.Text: It's not working. So the cookie only needs to work on the homepage.
Answers.UserDisplayName: Johannes Lamers
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-25T19:56:57.940Z
Answers.Text: So, this code is in your homepage template (not your layout)? And you want to redirect to /male or /female (as per your comment above) depending on the users gender? Can you access these url's directly when a) you're logged in or b) you're not logged in?
Answers.UserDisplayName: André Elvan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-25T20:00:35.767Z
Answers.Text: Yes its on the homepage. So after first visit the redirect gets me to the right page. But if I want to go back to the homepage there is the redirect again.
  
  So just one time a redirect. After that its up to the member.
Answers.UserDisplayName: Johannes Lamers
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-25T20:03:54.563Z
Answers.Text: Ah, now I get it... Yes, that would be the case. Let me update my answer.
Answers.UserDisplayName: André Elvan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-25T19:46:22.267Z
Answers.LastActivityDate: 2015-03-25T20:07:52.320Z
Answers.LastEditDate: 2015-03-25T20:07:52.320Z
Answers.UserDisplayName: André Elvan
Body: <p>How can I redirect a member to account page on first visit with a cookie set? My redirect is looping now. </p>
  
  <pre><code>{% if currentUser %}
     {% set name = currentUser.firstName %}
     {% do craft.lj_cookies.set('account', name) %}
  
  
  
     {% set redirect = craft.lj_cookies.get('account') %}
  
     {% if redirect == name %}
         {% redirect name %}
     {% endif %}
  
  {% endif %}
  </code></pre>
  
  <p>It's not possible to visit any other URL anymore.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-03-25T19:42:07.167Z
Comments.Text: You want to always redirect a user if they have a particular cookie value set?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-03-25T19:45:47.643Z
Comments.Text: The redirect to the account is just an example. In my case i'm working on a kind of webshop. My members need to fill in there gender. If they enter the site I want them to redirect to the shop with male (shop/male of shop/female) product. After the redirect is up to the member where to go next. Could me male products etc. So just 1 time redirect.
Comments.UserDisplayName: Johannes Lamers
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-03-25T19:47:03.807Z
Comments.Text: It's based on this anser: http://craftcms.stackexchange.com/questions/8816/return-to-specific-locale-based-on-cookie
Comments.UserDisplayName: Johannes Lamers
Tags: <redirect><member>
Title: How to set cookie and redirect to page one time
ThreadText: # How to set cookie and redirect to page one time
  
  (Asked by: username_0 on 2015-03-25)
  
  How can I redirect a member to account page on first visit with a cookie set? My redirect is looping now.
  
  ```
  {% if currentUser %}
     {% set name = currentUser.firstName %}
     {% do craft.lj_cookies.set('account', name) %}
  
     {% set redirect = craft.lj_cookies.get('account') %}
  
     {% if redirect == name %}
         {% redirect name %}
     {% endif %}
  
  {% endif %}
  
  ```
  
  It's not possible to visit any other URL anymore.
  
  **Tags:** redirect, member
  
  > **Comments:**
  > **username_1**: You want to always redirect a user if they have a particular cookie value set?  
  > **username_0**: The redirect to the account is just an example. In my case i'm working on a kind of webshop. My members need to fill in there gender. If they enter the site I want them to redirect to the shop with male (shop/male of shop/female) product. After the redirect is up to the member where to go next. Could me male products etc. So just 1 time redirect.  
  > **username_0**: It's based on this anser: http://craftcms.stackexchange.com/questions/8816/return-to-specific-locale-based-on-cookie  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-03-25. Score: 2 | Accepted answer
  
  Try this:
  
  ```
  {% if currentUser %}
      {% set name = currentUser.firstName %}
      {% if craft.lj_cookies.get('account') != name %}
          {% do craft.lj_cookies.set('account', name) %}
          {% redirect name %}
      {% endif %}
  {% endif %}
  
  ```
  
  In you're original code you're setting the cookie before getting it into the redirect variable, so the {% if redirect == name %} conditional is always true.
  
  > **Comments:**
  > **username_0**: It's not working. So the cookie only needs to work on the homepage.  
  > **username_2**: So, this code is in your homepage template (not your layout)? And you want to redirect to /male or /female (as per your comment above) depending on the users gender? Can you access these url's directly when a) you're logged in or b) you're not logged in?  
  > **username_0**: Yes its on the homepage. So after first visit the redirect gets me to the right page. But if I want to go back to the homepage there is the redirect again.  So just one time a redirect. After that its up to the member.  
  > **username_2**: Ah, now I get it... Yes, that would be the case. Let me update my answer.  
  
  ---
  
  