<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Set Cookie from URL Parameter and using it in HTML on a different page. in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Set-Cookie-from-URL-Parameter-and-using-it-in-HTML-on-a/m-p/4067#M385</link>
    <description>&lt;P&gt;I am setting up an affiliate link area for my site and need to be able to store a URL query string into a cookie that expires in a 7 days and pull it out into HTML later down the road.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Users will click on a link like: &lt;A href="http://examplesite.com/?afil=randomvalue" rel="nofollow noreferrer" target="_blank"&gt;http://examplesite.com?afil=randomvalue&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to pull the key 'afil' and the value 'randomvalue' and put it in a cookie in the browser.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This cookie will be used later (on another page) in a link from one of examplesite.com to order.examplesite.com but I can't keep the parameter (query string) in the URL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can do this on another site using PHP but HubSpot doesn't let me use PHP. I saw other posts mentioning the use of HUBL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My PHP code is:&lt;/P&gt;&lt;P&gt;&amp;lt;body&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;?php&lt;/P&gt;&lt;P&gt;$value=$_GET['afil']; //the value from the url&lt;/P&gt;&lt;P&gt;setcookie("afilCookie", $value, strtotime( '+7 days' )); /* expire in 7 days */&lt;/P&gt;&lt;P&gt;?&amp;gt;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And to create a link I would then add this code to any page:&lt;/P&gt;&lt;P&gt;if (isset($_COOKIE['afilCookie'])) {&lt;BR /&gt;$cookie = $_COOKIE['afilCookie'];&lt;BR /&gt;echo '&amp;lt;a href="&lt;A href="http://order.examplesite.com?afil=" target="_blank"&gt;http://order.examplesite.com?afil=&lt;/A&gt;' . $cookie . '" class="button"&amp;gt;Order Now&amp;lt;/a&amp;gt;';&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Can anyone help me with creating the correct code in HUBL to do all of this?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. Add a cookie with the key/value from the URL query string (parameter).&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. Pull the cookie value to use as a variable in a link.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very unfamiliar with it and haven't been able to find any posts that match this request.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Jan 2017 19:41:17 GMT</pubDate>
    <dc:creator>REVEALiO</dc:creator>
    <dc:date>2017-01-09T19:41:17Z</dc:date>
    <item>
      <title>Set Cookie from URL Parameter and using it in HTML on a different page.</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Set-Cookie-from-URL-Parameter-and-using-it-in-HTML-on-a/m-p/4067#M385</link>
      <description>&lt;P&gt;I am setting up an affiliate link area for my site and need to be able to store a URL query string into a cookie that expires in a 7 days and pull it out into HTML later down the road.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Users will click on a link like: &lt;A href="http://examplesite.com/?afil=randomvalue" rel="nofollow noreferrer" target="_blank"&gt;http://examplesite.com?afil=randomvalue&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to pull the key 'afil' and the value 'randomvalue' and put it in a cookie in the browser.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This cookie will be used later (on another page) in a link from one of examplesite.com to order.examplesite.com but I can't keep the parameter (query string) in the URL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can do this on another site using PHP but HubSpot doesn't let me use PHP. I saw other posts mentioning the use of HUBL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My PHP code is:&lt;/P&gt;&lt;P&gt;&amp;lt;body&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;?php&lt;/P&gt;&lt;P&gt;$value=$_GET['afil']; //the value from the url&lt;/P&gt;&lt;P&gt;setcookie("afilCookie", $value, strtotime( '+7 days' )); /* expire in 7 days */&lt;/P&gt;&lt;P&gt;?&amp;gt;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And to create a link I would then add this code to any page:&lt;/P&gt;&lt;P&gt;if (isset($_COOKIE['afilCookie'])) {&lt;BR /&gt;$cookie = $_COOKIE['afilCookie'];&lt;BR /&gt;echo '&amp;lt;a href="&lt;A href="http://order.examplesite.com?afil=" target="_blank"&gt;http://order.examplesite.com?afil=&lt;/A&gt;' . $cookie . '" class="button"&amp;gt;Order Now&amp;lt;/a&amp;gt;';&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Can anyone help me with creating the correct code in HUBL to do all of this?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. Add a cookie with the key/value from the URL query string (parameter).&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. Pull the cookie value to use as a variable in a link.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very unfamiliar with it and haven't been able to find any posts that match this request.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2017 19:41:17 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Set-Cookie-from-URL-Parameter-and-using-it-in-HTML-on-a/m-p/4067#M385</guid>
      <dc:creator>REVEALiO</dc:creator>
      <dc:date>2017-01-09T19:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: Set Cookie from URL Parameter and using it in HTML on a different page.</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Set-Cookie-from-URL-Parameter-and-using-it-in-HTML-on-a/m-p/4098#M389</link>
      <description>&lt;P&gt;HubSpot has told me that there is no way to set a cookie using PHP, Javascript, jQuery, or HubL. If anyone knows otherwise please let me know.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 00:06:54 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Set-Cookie-from-URL-Parameter-and-using-it-in-HTML-on-a/m-p/4098#M389</guid>
      <dc:creator>REVEALiO</dc:creator>
      <dc:date>2017-01-10T00:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Set Cookie from URL Parameter and using it in HTML on a different page.</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Set-Cookie-from-URL-Parameter-and-using-it-in-HTML-on-a/m-p/4133#M393</link>
      <description>&lt;P&gt;I don't see why you could not use JavaScript to set a cookie?&lt;/P&gt;&lt;PRE&gt;function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    var expires = "expires="+d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

setCookie("afil", "{{ request.query_dict.afil }}", 30);&lt;/PRE&gt;&lt;P&gt;I'd give it a try and see if it works!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 15:01:51 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Set-Cookie-from-URL-Parameter-and-using-it-in-HTML-on-a/m-p/4133#M393</guid>
      <dc:creator>ndwilliams3</dc:creator>
      <dc:date>2017-01-10T15:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: Set Cookie from URL Parameter and using it in HTML on a different page.</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Set-Cookie-from-URL-Parameter-and-using-it-in-HTML-on-a/m-p/4296#M402</link>
      <description>&lt;P&gt;To get just the value from a specific query field you can use this HubL:&lt;/P&gt;&lt;PRE&gt;{{ request.query.get('afil') }}&lt;/PRE&gt;&lt;P&gt;So if your URL looks like this: &lt;EM&gt;example.com/page?afil=randomkey&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;The code will return the string "randomkey". Of course you could also just do this without HubL at all and with just vanilla javascript.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2017 14:38:06 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Set-Cookie-from-URL-Parameter-and-using-it-in-HTML-on-a/m-p/4296#M402</guid>
      <dc:creator>stefen</dc:creator>
      <dc:date>2017-01-11T14:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: Set Cookie from URL Parameter and using it in HTML on a different page.</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Set-Cookie-from-URL-Parameter-and-using-it-in-HTML-on-a/m-p/4407#M418</link>
      <description>&lt;P&gt;I asked Hubspot and they said that they support Javascript but not when related to cookies&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2017 00:51:50 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Set-Cookie-from-URL-Parameter-and-using-it-in-HTML-on-a/m-p/4407#M418</guid>
      <dc:creator>REVEALiO</dc:creator>
      <dc:date>2017-01-12T00:51:50Z</dc:date>
    </item>
  </channel>
</rss>

