gpt4 book ai didi

Can't delete or change the value of a cookie set on website with PHP(无法使用PHP删除或更改网站上设置的Cookie的值)

转载 作者:bug小助手 更新时间:2023-10-25 17:37:25 29 4
gpt4 key购买 nike



So normally I have no problems with setting and unsetting cookies for my website. But for some reason I can't delete this cookie that was set on my website by Google AdSense. Basically I was asking my users for consent, so I could show them ads. But I made a fatal mistake and I would like to ask the users again. But AdSense placed a cookie on my website called FCCDCF.

因此,通常我在设置和取消设置我的网站的cookie时没有问题。但出于某种原因,我无法删除这个由Google AdSense在我的网站上设置的cookie。基本上,我是在征求我的用户的同意,这样我就可以向他们展示广告。但我犯了一个致命的错误,我想再问一次用户。但AdSense在我的网站上放了一个名为FCCDCF的cookie。


I use the following code to check for cookies and their value

我使用以下代码检查Cookie及其值


if(isset($_COOKIE)) {
var_dump($_COOKIE);
foreach($_COOKIE as $key => $val)
{
echo "cookie name: ".$key."<br /><br />Value: ".$val;
}
}

This returns the following (I changed the the numbers/letters for safety)

这将返回以下内容(为了安全起见,我更改了数字/字母)


cookie name: FCCDCF

Cookie名称:FCCDCF


Value: [null,null,null,["WJGBHDKJKNKSFAAEPA1326467585AkCBIAAgAUgQAgFIIAwAIFAAAAA42567869675425AAAAQQAAAAAIAAAAAAAAEAQ7567464563AAAAABAAAAAAAAAAAAAAAAAAAAgAA","1~","CP764359-1234-4321-1246-2SDFSDF34566"],null,null,[]]

值:[NULL,[“WJGBHDKJKNKSFAAEPA1326467585AkCBIAAgAUgQAgFIIAwAIFAAAAA42567869675425AAAAQQAAAAAIAAAAAAAAEAQ7567464563AAAAABAAAAAAAAAAAAAAAAAAAAgAA”,“1~”,“CP764359-1234-4321-1246-2SDFSDF34566”],NULL,NULL,[]]


Now I would normally think that I could easily delete this cookie by simply using setcookie("FCCDCF", "", time()-3600); - but this does not seem to be the case.

现在,我通常认为只需使用setcookie(“FCCDCF”,“”,time()-3600)就可以很容易地删除此cookie;-但情况似乎并非如此。


Apparently I do not know enough about cookies to find a solution for this. I have searched for hours now and tried a bunch of different solutions for deleting cookies for your website - but nothing worked so far.

显然,我对饼干的了解还不够,无法找到解决办法。我已经搜索了几个小时,现在尝试了一堆不同的解决方案删除您的网站的cookie-但没有工作到目前为止。


My problem is that my mistake cost my 60% of my revenue for this particular site and if this does not get fixed, the website will close, because it's an expensive website to keep running.

我的问题是,我的错误让我损失了这个网站60%的收入,如果这个问题没有得到解决,网站将关闭,因为这是一个维持成本高昂的网站。


Thank you

谢谢


EDIT with more details about the cookie and the code I'm using to get rid of it (also see image)

编辑更多关于Cookie和我用来去除它的代码的细节(参见图片)


Cookie details:

Cookie详细信息:


Name: FCCDCF

名称:FCCDCF


Value: [null,null,null,["CPx4kYAPx4kYAEsACBDADWCgAAAAAEPAAAZQAAAQaQD2F2K2kKFgPi2QWYAQBCujIEAhUAAAAkCBIAAgAUgQAgFIIAwAIFAAAAAAAAAQEgCQAAQABAAAIACAAAAAAAIAAAAAAAQQAAAAAIAAAAAAAAEAQAAIAAQAAAAIAABEhCAAQQAEAAAAAAAQAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAgAA","1~","34A656F2-7A38-4C75-88E5-06DDD813736B"],null,null,[]]

值:[NULL,[“CPx4kYAPx4kYAEsACBDADWCgAAAAAEPAAAZQAAAQaQD2F2K2kKFgPi2QWYAQBCujIEAhUAAAAkCBIAAgAUgQAgFIIAwAIFAAAAAAAAAQEgCQAAQABAAAIACAAAAAAAIAAAAAAAQQAAAAAIAAAAAAAAEAQAAIAAQAAAAIAABEhCAAQQAEAAAAAAAQAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAgAA”,“1~”,“34A656F2-7A38-4C75-88e5-06DDD813736B”],NULL,NULL,[]]


Domain: mydomain.com

域名:mydomain.com


Path: /

路径:/


Expires / Max-Age: 2024-10-04T20:35:11.000Z

过期/最大年龄:2024-10-04T20:35:11.000Z


Size: 343

尺寸:343


Priority: Medium

优先级:中等


Important: I have tried to overwrite the cookie by creating a new one

重要提示:我已尝试通过创建新的Cookie来覆盖该Cookie


I have tried to create a new cookie to see if this would automatically overwrite the current one. It doesn't - it just creates a new cookie with the exact same name (see image further down). I created this cookie like this: setcookie("FCCDCF", "testcookie...", time() + (86400 * 30), "/");

我已经尝试创建一个新的cookie,看看这是否会自动覆盖当前的cookie。它不会--它只会创建一个同名的新cookie(见下图)。我是这样创建这个cookie的:setcookie(“FCCDCF”,“testcookie...”,time()+(86400*30),“/”);


So what code am I using to delete the cookies

那么我该用什么代码来删除这些Cookie呢


First i simply tried this code: setcookie("FCCDCF", "", time() - (86400 * 30), "/"); - that didn't work.

首先,我简单地尝试了以下代码:setcookie(“FCCDCF”,“”,time()-(86400*30),“/”);-不起作用。


Next @ProfessorAbronsius asked me to set the cookie with the same value but with the time in the past which I did like this:

接下来@ProfessorAbrisius让我将Cookie设置为相同的值,但设置的时间是过去的时间,我是这样做的:


$CookieValue = $_COOKIE['FCCDCF'];
setcookie("FCCDCF", $CookieValue, time() - (86400 * 30), "/");

This is not working either. The cookie is still there. BUT it deletes the testcookie I set.

这也不管用。饼干还在那里。但它会删除我设置的测试曲奇。


Image:
enter image description here

图像:


THANK you for your time

谢谢您抽时间见我


更多回答

Where do you run the setcookie? It must be before outputting anything. Are you just trying to delete the cookie?

您在哪里运行setcookie?一定是在输出任何东西之前。你只是想删除这个曲奇吗?

set the cookie with the same parameters but with the time in the past.

使用相同的参数设置Cookie,但设置时间为过去的时间。

@user3783243 - I know you think I'm crazy because this should be pretty straightforward. I am setting the new cookie before anything else. Yes I would just try to delete the cookie - but everything I do does not work for this exact cookie called "FCCDCF". Actually I just checked the console I can see that whenever I make a new cookie called "FCCDCF" - it doesn't change the first one but rather makes ANOTHER one so I have 2 cookies called the exact same thing but with different values.

@user3783243-我知道你认为我疯了,因为这应该很简单。我把新的曲奇放在最重要的位置。是的,我只会尝试删除Cookie--但我所做的一切并不适用于这个名为“FCCDCF”的Cookie。事实上,我刚刚检查了控制台,我可以看到,每当我创建一个名为“FCCDCF”的新Cookie时-它不会更改第一个Cookie,而是生成另一个Cookie,所以我有两个Cookie,名称完全相同,但值不同。

Can you show the full code that you actually have to try to delete the cookie and the full details of the cookie please?

你能给我展示你删除Cookie的全部代码和Cookie的全部细节吗?

Is it possible that you successfully remove the cookie and AdSense recreates it? Can you temporarily switch off AdSense, try to remove the cookie and tell us whether the cookie goes missing then? Just a wild thought.

您是否可以成功删除Cookie,然后AdSense重新创建它?你能暂时关闭AdSense,尝试删除Cookie,然后告诉我们Cookie是否丢失了吗?这只是一个疯狂的想法。

优秀答案推荐

There is a somewhat similar issue to this over here.

这里有一个有点类似的问题。


The solution to delete the cookie provided in that post by Terry Burton is written in JavaScript and has a check to ensure the consent was given more than 12 months ago, but it may bring more insight as to how it should be done:

特里·伯顿在那篇帖子中提供的删除Cookie的解决方案是用JavaScript编写的,它有一个检查,以确保同意是在12个月前获得的,但它可能会带来更多关于如何做到这一点的见解:


<script>
// Delete the Funding Choices cookie if consent is more than 12 months old
try {
const nm = "FCCDCF"; // Match name of Funding Choices cookie
const dm = "mydomain.com"; // Match domain of Funding Choices cookie
const pa = "/"; // Match path of Funding Choices cookie
let tc = ('; ' + document.cookie).split('; ' + nm + '=');
if (tc.length === 2) {
tc = decodeURIComponent(tc.pop().split(';').shift());
tc = JSON.parse(tc)[3][0].substring(1,9);
tc = Uint8Array.from(window.atob(tc), (v) => v.charCodeAt(0));
let dt = (tc[0] * 2**28) + (tc[1] * 2**20) + (tc[2] * 2**12) +
(tc[3] * 2**4) + (tc[4] >> 4);
if (Date.now() / 1000 - dt / 10 > 86400 * 365)
document.cookie = nm + "=;path=" + pa + ";domain=" + dm +
";expires=" + new Date(0).toUTCString();
}
} finally {}
</script>>

The idea is to create a new cookie with the exact same data (name, domain, path, etc) and set its expiry to the current time so that it gets deleted.

其想法是使用完全相同的数据(名称、域、路径等)创建一个新的Cookie,并将其过期设置为当前时间,以便将其删除。


If I am misunderstanding and you already have tried this, do make sure that there are no other cookies saved on the browser with the name "FCCDCF", as they may interfere with your attempt at deleting the one created by AdSense.

如果我的理解有误,而您已经尝试过这样做,请确保浏览器上没有保存名为“FCCDCF”的其他cookie,因为它们可能会干扰您删除AdSense创建的cookie的尝试。



I found a solution including both PHP and JavaScript.

我找到了一种既包括PHP又包括JavaScript的解决方案。


January 16th, 2024 Google AdSense will introduce this new consent message and force it to all its accepted websites.

2024年1月16日,谷歌AdSense将推出这一新的同意消息,并强制其所有接受的网站。


I don't know why PHP can't delete this cookie

我不知道为什么PHP不能删除这个Cookie


As the user @Pmpkn already addressed in this question; people are already experiencing this problem and can't find a solution. See the thread here

正如用户@Pmpkn已经在这个问题中提到的;人们已经遇到了这个问题,并且找不到解决方案。请看这里的线索


Be aware!!

注意了!!


I only use this script because I made a fatal error at the beginning of the consent message. I won't force any of my users to consent. But I don't run a charity, so I can't let them use up resources that cost me a lot of money. So they can consent or leave the website.

我之所以使用这个脚本,是因为我在同意消息的开头犯了一个致命的错误。我不会强迫我的任何用户同意。但我不经营慈善机构,所以我不能让他们用完我花了很多钱的资源。所以他们可以同意或离开网站。


As you might know, Google let this cookie expire after 13 months. So it's a lot of time with no possibility to ask the users for consent again.

正如你可能知道的,谷歌让这个cookie在13个月后过期。因此,在很长一段时间内,没有可能再次请求用户同意。


I don't know if this is allowed in the ToS of Google AdSense - so beware of this. Use at own risk. On the other hand. Deleting a cookie on your OWN website should not be a problem in my opinion. I don't know though.

我不知道Google AdSense的ToS中是否允许这样做--所以要小心这一点。使用风险自负。从另一方面来说。在我看来,删除自己网站上的Cookie应该不是问题。不过,我不知道。


I introduce the solution

我介绍了解决方案


As simple as this script might seem - it's the only one working. I have tried every other PHP script - and my conclusion is clear: It just can't delete this specific cookie.

尽管这个脚本看起来很简单,但它是唯一有效的脚本。我已经尝试了所有其他的PHP脚本--我的结论很清楚:它只是不能删除这个特定的cookie。


<script>
var domainName = window.location.hostname;
document.cookie = "FCCDCF=...; expires=Tue, 16 Apr 2019 11:31:56 GMT; path=/; domain=." + domainName;
</script>

var domainName = window.location.hostname; Creates a variable called domainName which will get the exact domain name of the current website.

Var domainName=window.location.host名称;创建一个名为domainName的变量,该变量将获得当前网站的确切域名。


In the next line you will actually create the cookie with the values you wish. document.cookie is telling the browser to create a cookie. The following is just values for the specific cookie. I wan't to delete the Cookie called FCCDCF and therefore I name the new cookie exactly that with the value ... like this: FCCDCF=...;

在下一行中,您将实际创建具有所需值的Cookie。Cookie告诉浏览器创建一个cookie。以下只是特定Cookie的值。我不想删除名为FCCDCF的Cookie,因此我将新Cookie命名为…像这样:FCCDCF=...;


I end the value with a semicolon. After the semicolon, I can then put in another detail of the cookie. In this case I put in expires=Tue, 16 Apr 2019 11:31:56 GMT; So the date is 4 years ago and therefore the cookie should delete itself.

我以分号结束该值。在分号之后,我可以放入cookie的另一个细节。在本例中,我输入Expires=Tue,2019年4月16日11:31:56 GMT;因此日期是4年前,因此Cookie应该会自动删除。


Next I put in the path like this: path=/;

接下来,我放入如下路径:Path=/;


This next step is very important. I need to use the variable I created and put it in the cookie. But! Look out for the . before the variable. The . before the domain is very much needed, because AdSense creates the cookie with a dot before it, so the cookie also is included in sub domains.

这下一步非常重要。我需要使用我创建的变量并将其放入Cookie中。但!当心。在变量之前。那就是。之前的域名是非常需要的,因为AdSense创建的Cookie前面有一个圆点,所以Cookie也包括在子域中。


So it should look like this: domain=." + domainName;

因此,它应该如下所示:DOMAIN=.“+DomainName;


The problem with this script alone

仅此脚本的问题就在于


So this script successfully deletes the cookie called FCCDCF and that's great. But the thing is that it deletes the cookie every single time the page is refreshed or the visitor is clicking around on the website. This could be pretty annoying to accept cookies on every page view.

因此,此脚本成功删除了名为FCCDCF的Cookie,这很好。但问题是,每当页面刷新或访问者在网站上四处点击时,它都会删除Cookie。在每个页面浏览量上都接受Cookie可能会非常烦人。


I solved this by looking at the value of the FCCDCF-cookie when someone did consent and when someone didn't consent.

当有人同意和有人不同意时,我通过查看FCCDCF-Cookie的价值解决了这个问题。


The value of the cookie when someone consents, is around ~800 characters long - give or take.

如果有人同意的话,Cookie的价值大约是800个字符--或多或少。


When someone does not consent** the value of the cookie is only around ~300 characters.

当有人不同意**时,Cookie的值只有大约300个字符。


So with PHP I would simply take the value of the cookie and count the characters of this exact cookie. If the characters of the cookie are lower than 600 characters (which means that they did not consent) - I would show the consent message again.

因此,在使用PHP时,我只需获取Cookie的值并计算该Cookie的字符。如果Cookie的字符少于600个字符(这意味着他们不同意)-我将再次显示同意消息。


The complete script that I made

我做的完整的剧本


<?php
$CookieValue = $_COOKIE['FCCDCF'];

$CookieChar = strlen($CookieValue);

if($CookieChar < "600") {
?>
<script>
var domainName = window.location.hostname;
document.cookie = "FCCDCF=...; expires=Tue, 16 Apr 2019 11:31:56 GMT; path=/; domain=." + domainName;
</script>
<?php
}
?>


I imagine you tried to delete it in Javascript :

我想你是想用Java脚本把它删除:


document.cookie = "FCCDCF=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";

And what happens when you Application > Cookies > right-click on site url > clear in the browser inspector ?

在浏览器检查器中,当应用程序>Cookie>右键单击站点URL>清除时,会发生什么情况?


enter image description here


更多回答

Thank you for your answer. I have already tried this and it's not working either. I appreciate it though. It simply does not delete or edit anything which highly frustrates me.

谢谢你的回答。我已经试过了,它也不起作用。不过,我还是很感激。它根本不会删除或编辑任何让我非常沮丧的东西。

Apparently, the following was meta-commentary and was edited out: "I am highly disappointed that I would get downvotes for this question. I don't understand why and as people can read and tell - I have tried a bunch of different stuff and done some research also. And trust me. January 16th, 2024 Google AdSense will introduce this new consent message and force it to all its accepted websites. And there will be a lot of people asking the same questions in the following months. I feel like this should be included though. Even in a comment. Even the editor didn't upvote this question.

显然,以下内容是元评论,并被删掉了:“我对这个问题的反对票感到非常失望。我不明白为什么,正如人们读到的那样--我尝试了很多不同的东西,也做了一些研究。相信我。2024年1月16日,谷歌AdSense将推出这条新的同意消息,并强制其在其所有被接受的网站上使用。在接下来的几个月里,将会有很多人提出同样的问题。但我觉得这应该包括在内。即使是在评论中。就连编辑也没有支持这个问题。”

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com