-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
One time Cookie Notice #65
Comments
Seems that this issue only happens on the community site; |
Hmm, I cannot reproduce this on our community. The notice does not appear again for me. |
I have the same as @ArchBlood on my phone (Android 13) with Chrome, and (Chrome-based) PWA. |
I can confirm that the issue is also happening on Chrome mobile browser as well. |
@yurabakhtin Can you please take a look into it? |
@luke- I have the same bug today when I open https://community.humhub.com in Chrome on Windows 11. I find 2 cookie records: If manually remove the 2 records then it works as expected, i.e. after first click "Got it!" the cookie block is hidden and doesn't appears again.
The cookie block is initialized by this JS library https://www.osano.com/cookieconsent/documentation/javascript-api/ |
Can't we just use something like this to set the cookie domain? // Set the cookie to a specific domain
$cookieDomain = \yii\helpers\Url::base()'; // Replace 'yourdomain.com' with your desired domain
setcookie('cookieconsent_status', 'accepted', time() + 31536000, '/', $cookieDomain, false, true); Or something like the following? // Get the current site's domain
$currentDomain = Yii::$app->request->hostInfo;
// Set the cookie using Yii's response component
$response = Yii::$app->response;
$response->cookies->add(new \yii\web\Cookie([
'name' => 'cookieconsent_status',
'value' => 'accepted',
'expire' => time() + 31536000,
'path' => '/',
'domain' => $currentDomain,
'httpOnly' => true,
'secure' => true, // Set to true if your site uses HTTPS
])); We should be able to do this in |
Another option would be the following; <?php
namespace humhub\modules\legal\widgets;
use humhub\components\Widget;
use humhub\modules\legal\models\Page;
use Yii;
use yii\web\HttpException;
/**
* Class CookieNote
* @package humhub\modules\legal\widgets
*/
class CookieNote extends Widget
{
public function run()
{
$page = Page::getPage(Page::PAGE_KEY_COOKIE_NOTICE);
if ($page === null) {
return "";
}
// Get the current site's domain
$currentDomain = Yii::$app->request->hostInfo;
// Extract the root domain to cover all subdomains and aliases
$rootDomain = $this->getRootDomain($currentDomain);
// Set the cookie using Yii's response component
$response = Yii::$app->response;
$response->cookies->add(new \yii\web\Cookie([
'name' => 'cookieconsent_status',
'value' => 'accepted',
'expire' => time() + 31536000,
'path' => '/',
'domain' => $rootDomain,
'httpOnly' => true,
'secure' => true, // Set to true if your site uses HTTPS
]));
return $this->render('cookies', ['page' => $page]);
}
// Function to extract the root domain from a given domain
private function getRootDomain($domain)
{
$domainParts = explode('.', $domain);
$partsCount = count($domainParts);
if ($partsCount > 2) {
// Construct the root domain for subdomains or alias domains
$rootDomain = $domainParts[$partsCount - 2] . '.' . $domainParts[$partsCount - 1];
return '.' . $rootDomain;
}
return $domain; // Return original domain if it's already a root domain
}
} Although I've not tested this specific method. |
@ArchBlood Thank you for the help, but the problem was from JS side. This fix will hides the cookie consent window on all browsers even if they still have two records for root domain and for the strange records with domain like I have compared the JS method const getCookie = name => {
const value = ' ' + document.cookie;
const parts = value.split(' ' + name + '=');
return parts.length < 2 ? undefined : parts.pop().split(';').shift();
}; and from the humhub file version: getCookie: function (e) {
var t = "; " + document.cookie,
i = t.split("; " + e + "=");
return 2 != i.length ? void 0 : i.pop().split(";").shift();
}, so the difference was between My fix is a manual updating only of the code, because I tried to use new version completely from here https://github.com/osano/cookieconsent/blob/dev/build/cookieconsent.min.js and I updated the initialisation code from |
@yurabakhtin Thanks. I'll keep this issue open, because we should find a better solution in future, instead of fixing the minifed version. |
Currently when you visit a HumHub instance with cookie notice enabled you have to accept each time you visit the site.
The text was updated successfully, but these errors were encountered: