Getting Cookies and passing them to an endpoint

Hello everyone,

I’m currently building a HTML5 quiz game, the game is to be hosted on a site. Now, each time a user plays the game, and scores a point, I’ve written a function that sends that score to the site where it is added to the players leaderboard.

Now, how do the site know the userId of the player whose score has been passed to the endpoint so It could add it accordingly.

It was suggested that I get the site’s cookies within the game and pass it in the header during the network request.

Does anybody know how I could get the cookies in corona sdk?
I have very little knowledge about web development.

1 Like

Thanks XeduR, you’ve been a great help to me. The last time we spoke, I didn’t know how to use the network request api or even the hash api, you showed me the way, I truly appreciate that.

I’ve downloaded that plugin, I wasn’t sure if it would work. In my case, I’m not setting a cookie, I’m simply trying to get the cookies that has been set by the site and send it back to them.

So, if I use this plugin, put it in the first page of the game and call only the “get cookies” function, would it get the cookies of the site which it is hosted in?

I’m sorry for the many questions, I’m not good with web development.

I haven’t tried that plugin myself yet, I just know of it and that its author produces quality work.

If you are setting cookies on the site and you just need to pass them to your app, then you could write a JavaScript plugin (see: https://docs.coronalabs.com/guide/html5/plugins/index.html) and use that to pass the cookies to the app.

1 Like

Thanks. But, since the web developers are the ones setting the cookies, and they are hosting the HTML5 games on the site, shouldn’t they be able to get get the cookies from any user who plays the game?

For example, User A and User B both log into the website and open the game. Once the game is opened on both phones, a network request is sent. Shouldn’t the site be able to differentiate each user’s request since, they are both still logged in to the site.

Shouldn’t the site be able to just get the cookies of the browser sending the request without the Game doing any of that, because they are still logged in and active on the site.