i am trying to set a cookie for the users who signup with the newsletter pop in magento home page
i have a pop in magento homepage with a newsletter subscription option when user subscribes to the newsletter a cookie is set to that the newsletter will not show him on next visit
here is the code how am setting the cookie
<?php
$value=$_POST['newslettertext'];
setcookie("EmailCookie", $value);
setcookie("EmailCookie", $value , time()+86400,"/");
function gotopage($url)
{
echo "<script language=\"javascript\">";
echo "window.location = '".$url."'; \n";
echo "</script>";
}
$url="http://abc.com";
gotopage($url);
?>
the above code sets a coookie
after subscription the user redirects to the same page there i have check if cookie is set then the popup code executes otherwise there will be non popup
but its still showing the popup after subsscription
am using this code to check cookie
<?php
if(!isset($_COOKIE['EmailCookie'] ) )
{
//popup code goes here
}
?>
where am doing wrong ?
In this article we learn how to Set, get and delete data from cookie in Magento2. So first, Create a folder “Cookie” under app/code/Namespace/Module/ and create a file “Custom. php” under app/code/Namespace/Module/Cookie/. In the above code, I have created a function get() that is used to get data stored in cookie.
The Cookie Notice module allows selecting cookie notice display type and modifying the layout of the bar or the popup making them match the Magento theme. The extension ensures users that the Magento 2 store abides by the EU's cookie law and hence win their trust.
Magento 2 Default Cookies. The following cookies are used by Magento Commerce “out of the box” for on-premise and cloud installations. These cookies may be required by functionality that is explicitly requested by the customer. To learn about the lifetime of session cookies, see Session Lifetime.
require_once 'Mage.php';
Mage::app();
$cookie = Mage::getSingleton('core/cookie');
$cookie->set('cookiename', 'cookievalue' ,time()+86400,'/');
here is the answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With