Is there a service method I can use to get (any kind of) session data by giving the cookies CraftSessionId as a parameter?

if would look something like this. craft()->userSession->getSessionBySessionId($craftSessionId)

  • What are you trying to accomplish? Are you thinking there would be multiple PHP sessions for a user? Or are you just looking to see how to read from and write to session?
    – Brad Bell
    Mar 17, 2016 at 22:29
  • Im using the ElementAPI (github.com/pixelandtonic) . I see that you wrote it. Great :-). Mar 17, 2016 at 22:45
  • So with this plugin I want to make a json API for Android and IOS apps. I want to create API urls to log the user in and authenticate the user. Mar 17, 2016 at 23:00
  • I wanted to use craft()->userSession methods for this in the API but since this uses php SESSION I thought that it will only work when you visit the page with a browser, not when making calls from Android and IOS apps. eg. craft()->userSession->isLoggedIn I dont think will work in this case (am I correct?). So I want to make a API url that can log the user in, and give some kind of a session id in the response. Then the device can make other api calls and include this session id so that I can authenticate each call the user makes. Is this the way to go about it? Do you have any suggestions? Mar 17, 2016 at 23:06
  • @SiteHopper I'm attempting to do exactly the same thing - I'm using the ElementAPI for a client side app and would like to authenticate api calls. Did you find a solution? Jul 27, 2016 at 0:35

1 Answer 1


I don't think I'd use PHP's session for this at all, but recently posted some thoughts on a similar question here https://craftcms.stackexchange.com/a/14188/57 about using custom tokens or authorization headers to perform the authorization.

  • Thanks Brad. I am now working on expanding the plugin with a function that creates a custom token. Mar 18, 2016 at 9:49
  • 1
    If you can share it, would love to see what you come up with when you're done!
    – Brad Bell
    Mar 18, 2016 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.