Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Silverstripe and Cookies


Go to End


3 Posts   3049 Views

Avatar
sca123

Community Member, 61 Posts

17 January 2012 at 6:31am

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.

Avatar
_Vince

Community Member, 165 Posts

20 January 2012 at 12:04am

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

Avatar
Willr

Forum Moderator, 5523 Posts

20 January 2012 at 3:49pm

@_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?