Jump to content

Check Cookie is set from the module by using its method


prestashop_newuser

Recommended Posts

Hi,

I am developing a module in Prestashop 1.6.X . In this module I am setting a custom cookie using js. 

Now in the module php file I am  checking if the cookie is set then do something. So for that I am doing this code



if (isset( $_COOKIE['mycookie'] )) { 
echo 'hello';
}


Here mycookie is the cookie name that I have made set using js.Its working fine. But when I am trying to validate the module its showing error. It is showing error like


The use of $_COOKIE is forbidden; use Context::getContext()->cookie instead

. So can someone tell me how to check the cookie name by using Context::getContext()->cookie.

 

I have tried 

Context::getContext()->cookie('mycookie')

.But its not working. 

Any help and suggestions will be really appreciable. Thanks

Link to comment
Share on other sites

  • 1 year later...

Does that code check if cookie exists or not?

If yes, then its not the solution I'm looking for.

 

My question is very well explained in first post of this topic.

 

Below is my code in JS file.

$('.apply').click(function() {
   $.cookie('MyName', 'John');
});

 

Currently, I use below code in PHP file.

if ( isset($_COOKIE['MyName']) ) {
   $_COOKIE['MyName'];
}

It works perfect but using $_COOKIE shows error while validating the module.

 

So, how to get this cookie in module's PHP file?

Edited by roo10 (see edit history)
Link to comment
Share on other sites

Sorry, I thought you were just trying to check whether the PrestaShop cookie exists using the Cookie class. It's impossible to use the Cookie class to load a custom cookie. You should consider adding your custom variables to PrestaShop's cookie instead of a separate cookie.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...