Help! Cookies and javascript for affiliate program creation

Asked

Viewed 49 times

0

I need to create an affiliate program, where every registered affiliate will receive a single link with a link related to their ID in DB, for example:

example.com/affiliated? 4312123

I need to create cookies valid for 30 days, that when the user who accesses the site for the first time through the affiliate link, will be saved and later if it comes to completing a form, this form capture in a hidden field the affiliate ID.

How can I do this? Thank you

  • From a read: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies

1 answer

0


You can do this right in Javascript, when you render the document, take the link hash, and save the coockie.

var url = "exemplo.com/afiliadoid?4312123";
var parametrosDaUrl = url.split("?")[1]; (4312123)

setcookie("CookieAfiliado", parametrosDaUrl, 30);  

Then apply logic to get. The application logic after 30 days you will have to analyze, because it will cancel itself when it expires. It has N ways to do, I would end up going elsewhere, stored data via database, controlling validity time in the back-end, providing user and password.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.