Jump to:

23371 Posts in 18161 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » Silverstripe and Cookies

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1076 Views
  • sca123
    Avatar
    Community Member
    61 Posts

    Silverstripe and Cookies Link to this post

    Hi

    I'm creating a cookie called "parentid" using a PHP script outside of Silverstripe. My browsers confirm that the session has been created correctly.

    I'm now trying to access this within Silverstripe, using the following code:

    public function getParentID() {
    if (isset($_COOKIE['parentid'])) {
    return $_COOKIE['parentid'];
    }
    }

    Then in the template using $getParentID

    However, the code refuses to get the session content.

    Any help would be appreciated.

  • _Vince
    Avatar
    Community Member
    158 Posts

    Re: Silverstripe and Cookies Link to this post

    Is the function actually being called?

    If you return something like "hello" instead of the session content, does it work?

    I had to use cookies once and I got the contents like this:

    $OrderCookie = new Cookie;
    $Order = $OrderCookie->get('order_cookie');

    //process $Order here

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Silverstripe and Cookies Link to this post

    @_Vince Cookie is designed to be static.

    Cookie::set('foo', "Hello");
    Cookie::get('foo'); // returns hello.

    @sca123 - Are both your PHP script and SilverStripe running on the same domain?

    1076 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.