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

Integrate SilverStripe User Classes into Existing App


Go to End


5 Posts   651 Views

Avatar
Lazarus404

Community Member, 72 Posts

12 October 2011 at 4:50am

Hey guys,

I posted this question to the migration forum, but I think that might have been the wrong place.

I have a SilverStripe app and, alongside it, a different non-SilverStripe PHP app. I'd like to update parts of the non-SilverStripe app to check whether a user is logged in to the SilverStripe app and have it query for user information. How do I go about doing this?

Thanks,
Lee

Avatar
Lazarus404

Community Member, 72 Posts

12 October 2011 at 10:24am

Anyone?

Avatar
Lazarus404

Community Member, 72 Posts

12 October 2011 at 9:05pm

Surely someone's had to do this? Essentially, I'm simply using Sapphire classes in existing PHP classes. What do I need to include to make this work? Do I need to make the existing PHP classes extend anything?

Thanks,
Lee

Avatar
Willr

Forum Moderator, 5523 Posts

18 October 2011 at 5:34pm

You could try a couple ways of doing this, require the code directly. If you do a require for sapphire/main.php that should load in quite a few classes on your behalf but this could fail as it expects to be passed a direct web request. Otherwise you could make your custom code check for the session values SS sets. I assume your PHP is running on the same PHPSESSION so you should be able to use $_SESSION directly in your code to see if the user is logged in.

You could create a basic API for sending information to your application i.e a custom controller which returns the user information in JSON. You could then load the controller via CURL.

<?php

class Public extends Controller {

function member() {
return json_encode(Member::currentUser());
}
}

Hitting yoursite.com/Public/member with a curl request will then return the JSON object for the currently logged in member. Of course this will only work if you share the same session ID as the app itself.

Avatar
Lazarus404

Community Member, 72 Posts

18 October 2011 at 7:41pm

I thought of the latter, and tried it, but they didn't play ball. The newer app simply created a new session. Thhe first idea was getting frustrating as I needed a lot of SS features. In the end, I had the client side pull data via Ajax and then validated it server side in both locations. It's fiddly and not ideal, but secure.

Thanks for the advice, tho.

Lee