Reputation: 646
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 ?
Upvotes: 11
Views: 38206
Reputation: 646
require_once 'Mage.php';
Mage::app();
$cookie = Mage::getSingleton('core/cookie');
$cookie->set('cookiename', 'cookievalue' ,time()+86400,'/');
here is the answer
Upvotes: 32
Reputation: 167
Here is the solution:
Mage::getModel('core/cookie')->set($name, $value, $period, $path, $domain, $secure,$httponly);
There are 7 parameters where name and value are mandatory; other parameters are optional and can be set as null. Let’s see it one by one.
$name= Cookie name
$value= Cookie Value
$period= Cookie expire date (by default the period is set as 3600 seconds)
$path= Cookies path
$domain= Cookies domain
$secure= Cookies Security
$httponly= Http only when yes
Upvotes: 7