mukund002
mukund002

Reputation: 123

Not able to get cookie value on other page in magento

Hi I have set a cookie in Magento as:

$cookie_value = $_GET["utm_source"];
$cookie = Mage::getSingleton('core/cookie');
$name   = "Pixel_Track";
$url    = "stage.test.com";
$expiry = time() + 86400 * 365 * 1;
$cookie->set($name, $cookie_value ,$url,$expiry);

Now I want to get on another page and I am using:

$cookie = Mage::getSingleton('core/cookie')->get($name);

Where I am doing wrong? Because print_r is not giving the cookie name.

Upvotes: 0

Views: 2777

Answers (3)

Chaitanya Akhil
Chaitanya Akhil

Reputation: 1

Try this:

echo $cookie = Mage::getModel('core/cookie')->get("Pixel_Track");

//your can't get your variables in another page, so please type cookie name.

Upvotes: 0

mukund002
mukund002

Reputation: 123

I just got the solution by defining the path attribute of cookie.

$cookie->set($name, $cookie_value ,time()+86400,'/');

Upvotes: 0

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

Mage_Core_Model_Cookie class contains functions to set, get and delete cookie. so try:

$cookie_value = $_GET["utm_source"];
$cookie = Mage::getModel('core/cookie');
...
$cookie->set($name, $cookie_value, $period ,$url,$expiry);

and

$cookie = Mage::getModel('core/cookie')->get($name);

Upvotes: 1

Related Questions