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

CC BY-SA 3.0
2016-03-18T09:49:23.147Z
Thanks Brad. I am now working on expanding the plugin with a function that creates a custom token.
Rbijker.com
CC BY-SA 3.0
2016-03-18T22:59:33.103Z
If you can share it, would love to see what you come up with when you're done!
Brad Bell
CC BY-SA 3.0
2016-03-18T00:33:39.900Z
2016-03-18T00:33:39.900Z
2017-04-13T12:51:00.160Z
Brad Bell
<p>Is there a service method I can use to get (any kind of) session data by giving the cookies CraftSessionId as a parameter?</p>

<p>if would look something like this. 
<code>craft()-&gt;userSession-&gt;getSessionBySessionId($craftSessionId)</code></p>

CC BY-SA 3.0
2016-03-17T22:29:28.673Z
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
CC BY-SA 3.0
2016-03-17T22:45:07.950Z
Im using the ElementAPI (https://github.com/pixelandtonic/) . I see that you wrote it. Great :-).
Rbijker.com
CC BY-SA 3.0
2016-03-17T23:00:14.017Z
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.
Rbijker.com
CC BY-SA 3.0
2016-03-17T23:06:03.277Z
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?
Rbijker.com
CC BY-SA 3.0
2016-07-27T00:35:36.530Z
@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?
Adam Soffer
<plugin-development><craft-pro>
get session data by cookies CraftSessionId
# get session data by cookies CraftSessionId

(Asked by: username_0 on 2016-03-17)

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)`

**Tags:** plugin-development, craft-pro
> **Comments:**
> **username_1**: 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?  
> **username_0**: Im using the ElementAPI (https://github.com/pixelandtonic/) . I see that you wrote it. Great :-).  
> **username_0**: 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.  
> **username_0**: 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?  
> **username_2**: @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?  

---

## 1 answers

### Answer by username_1 on 2016-03-18. Score: 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.

> **Comments:**
> **username_0**: Thanks Brad. I am now working on expanding the plugin with a function that creates a custom token.  
> **username_1**: If you can share it, would love to see what you come up with when you're done!  

---

