time() + (13 * 30 * 24 * 60 * 60): This represents the expiration time of the cookie. The time() function returns the current timestamp in seconds since the Unix Epoch. In this case, we add the duration of 13 months to the current time by multiplying the number of seconds in a month (30 * 24 * 60 * 60) and adding it to the current timestamp. This ensures that the cookie will expire 13 months from the current time.
'/': This represents the path on the server where the cookie is available. In this case, it is set to '/', which means the cookie will be accessible across all paths on the server.
'.yoursite.com': This represents the domain for which the cookie is valid. In the provided code, it is set to '.yoursite.com', but you should replace it with your brand's actual top-level domain. By setting the domain to 'yoursite.com', the cookie will be accessible by any subdomain of yoursite.com.
false: This represents the "Secure" flag of the cookie. When set to false, it means the cookie can be transmitted over both secure (HTTPS) and non-secure (HTTP) connections. If set to true, the cookie will only be transmitted over secure connections.
false: This represents the "HttpOnly" flag of the cookie. When set to false, it means the cookie can be accessed by client-side scripts. If set to true, the cookie will be inaccessible to client-side scripts, enhancing the security of the cookie against cross-site scripting (XSS) attacks.
These constant values define the behavior and characteristics of the cookie that will be set. You can modify them based on your specific requirements and security considerations.
if (request.getParameter("adp_cid") != null) {
String adp_cookie_value = request.getParameter("adp_cid") + "_" + request.getParameter("adp_oid");
Cookie adpCookie = new Cookie("_adp", adp_cookie_value);
adpCookie.setSecure(false);
adpCookie.setHttpOnly(false);
adpCookie.setPath("/");
// adpCookie.setDomain(".yoursite.com"); // This is optional line if you choose this line beside setPath please change with brand top level domain
adpCookie.setMaxAge(13 * 30 * 24 * 60 * 60); // 13 months in seconds
response.addCookie(adpCookie);
}
Please note: This Java code assumes that the request and response objects are available in the current scope and that they are of types HttpServletRequest and HttpServletResponse, respectively. Additionally, you will need to import the javax.servlet.http.Cookie and javax.servlet.http.HttpServletRequest classes.
If Request.QueryString("adp_cid").Count > 0 Then
Dim adp_cookie_value
adp_cookie_value = Request.QueryString("adp_cid")(0) & "_" & Request.QueryString("adp_oid")(0)
Response.Cookies("_adp") = adp_cookie_value
Response.Cookies("_adp").Domain = ".yoursite.com" ' change with brand top level domain
Response.Cookies("_adp").Expires = DateAdd("m", 13, Now)
Response.Cookies("_adp").HttpOnly = False
Response.Cookies("_adp").Secure = False
End If
Please note: This VBScript code assumes that the Request and Response objects are available in the current scope and that they are of types ASP.Request and ASP.Response, respectively. Additionally, you may need to adjust the Domain property of the Response.Cookies("_adp") object to match your brand's top-level domain.
In PHP, we use the $_GET superglobal array to access query parameters. The isset() function checks if the "adp_cid" parameter is present, and the !empty() function ensures that it has at least one value.
The setcookie() function is used to set the "_adp" cookie. The parameters are as follows:
"_adp": The name of the cookie.
$adp_cookie_value: The value of the cookie, concatenated from "adp_cid" and "adp_oid" query parameters.
time() + (13 * 30 * 24 * 60 * 60): The expiration time of the cookie, set to 13 months from the current time.
`'/': The path on the server where the cookie is available.
'.yoursite.com': The domain for which the cookie is valid. Change it to your brand's top-level domain.
false: The "Secure" flag, which indicates if the cookie should only be sent over HTTPS.
false: The "HttpOnly" flag, which prevents client-side scripts from accessing the cookie.
Please note that the provided code assumes the existence of the "adp_oid" query parameter as well. If it's not always present, you may need to add additional checks before accessing $_GET['adp_oid'][0] to avoid errors.
<script>
// ALL Pages altında çalışacak kod bloğu
function createAdpCookie() {
var adpCid = getQueryParam("adp_cid");
if (adpCid !== null) {
var adpOid = getQueryParam("adp_oid");
var cookieValue = adpCid + "_" + adpOid;
var expires = new Date();
expires.setMonth(expires.getMonth() + 13);
var domain = window.location.hostname;
domain = domain.startsWith("www.") ? domain.substring(4) : domain;
domain = "." + domain;
document.cookie = "_adp=" + cookieValue + "; expires=" + expires.toUTCString() + "; domain=" + domain + "; secure; SameSite=None";
console.log("Adpartners Cookie oluşturuldu: " + cookieValue);
}
}
function getQueryParam(name) {
var urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}
createAdpCookie();
</script>
Descriptions:
getQueryParam(name): This is a JavaScript function that retrieves a querystring parameter. Here are the explanations for this function:
getQueryParam(name): This function takes a specific parameter name (e.g., "adp_cid" or "adp_oid") and examines the page's querystring to find this parameter.
var urlParams = new URLSearchParams(window.location.search);: This line creates a URLSearchParams object to work with the querystring of the current page.
return urlParams.get(name);: This line retrieves and returns the value of the specified parameter using the parameter name. If the parameter is not found, it returns null.
createAdpCookie(): This JavaScript function is used to create an adpartners cookie. Here are the explanations for this function:
var adpCid = getQueryParam("adp_cid");: In this line, the parameter "adp_cid" is retrieved from the querystring and stored in the adpCid variable.
if (adpCid !== null) { ... }: This if condition checks whether adpCid is null. If adpCid is not null, the cookie creation process is executed.
var adpOid = getQueryParam("adp_oid");: If the "adpCid" value is not null, this line retrieves the "adp_oid" parameter from the querystring and stores it in the adpOid variable.
var cookieValue = adpCid + "_" + adpOid;: The values of "adpCid" and "adpOid" are concatenated with an underscore character to form the value of the cookie.
var expires = new Date(); expires.setMonth(expires.getMonth() + 13);: These lines set the cookie's duration to 13 months.
var domain = window.location.hostname; ...: The domain for the cookie is extracted from the page's hostname and formatted accordingly.
document.cookie = "_adp=" + cookieValue + "; expires=" + expires.toUTCString() + "; domain=" + domain + "; secure; SameSite=None";: In this line, a cookie named "_adp" is created with the specified properties (duration, domain, security, etc.).
console.log("Adpartners Cookie created: " + cookieValue);: Finally, the value of the created cookie is logged to the console, providing information to the user.