ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How do I check if a cookie is set

March 02, 2012 10:22am

Subscribe [1]
  • #1 / Mar 02, 2012 10:22am

    brash

    10 posts

    How do I check if a Cookie is set? The following doesn’t seem to work:

    if(!isset($this->EE->input->cookie(“cookieName”))){
    $this->EE->functions->set_cookie("cookieName", "test", $expireTime);
    }


    I can’t seem to find much information on this. Guidance required. Thanks.

  • #2 / Mar 02, 2012 5:27pm

    Robin Sowell

    13255 posts

    Ah- that one is a bit trick- check the docs on the input class and Fetching a Superglobal- which boils down to - if it doesn’t exist, it will return false.

    So basically, this would work:

    if( ! $this->EE->input->cookie("cookieName"))
    {
      $this->EE->functions->set_cookie("cookieName", "test", $expireTime);
    }

    That help clarify?

  • #3 / Mar 06, 2012 4:16am

    brash

    10 posts

    Yup, that worked ! Thanks.

  • #4 / Mar 06, 2012 1:37pm

    Robin Sowell

    13255 posts

    😉  Glad you got it working!  Anything else comes up?  Just let us know.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases