Jump to content

Set custom cookie for specific groups


Graeme S.

Recommended Posts

Hi all,

I've had a look around but this is something that's out of my technical expertise. I am using Ezoic to serve ads on my site and I want to hide ads for subscribers. I can do this by setting up a custom cookie (e.g. Cookie called WebsiteEzoicAds with value NoAds). Then I would just tell Ezoic to hide ads from users with that cookie.

I know how to trigger code for certain groups, but not sure what to use to create/set the new cookie

{{if in_array( member.member_group_id, array(2,4,3) )}}
// Set cookie in here

{{endif}}

 

Link to comment
Share on other sites

{{if in_array( member.member_group_id, array(2,4,3) )}}
{{\IPS\Request::i()->setCooke( 'name', 'value' );}}
{{endif}}

Note that name will have a prefix (ips4_ by default) using this method. Also, this would result in a cookie only readable by HTTP...if you need it available for javascript, you would need to call ->setCookie( 'name', 'value', NULL, TRUE ); And finally, that NULL there in my last example is the expiration - by default the method will set a cookie only for the current browser session (so it will be cleared when you close the browser). If you need the cookie to persist, you would need to pass an \IPS\DateTime object there representing the expiration.

Or you could just use the core php method instead of our setCookie() wrapper if you need some more control.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...