1

Here is my ideal situation. I log into www.philstockworld.com using chrome. Once logged in I start up my java application that uses the cookies just stored by chrome. Then my java application goes to work. So here is my question.

Here is what my program can do now, I can login to the website using whatever browser I want, then look up the value of the PHPSESSID cookie and start up my app using that value. Then my app can do what it needs to. I can also supply my app with my username and password and have it log in, then store the returned PHPSESSID cookie and do what it needs to. However, what I would like to have happen is I login to the website using a browser, then my app starts and uses the PHPSESSID cookie from my browser session, without me having to look it up and copy it.

Is there a way for my java application to get the value of that cookie, without me having to manually type it in?

craigzooka
  • 13
  • 1
  • 4
  • 1
    Are you talking about a standalone Java application that runs on the desktop? – Carles Barrobés Nov 26 '10 at 19:51
  • Have you considered to just login using the same credentials in the Java application alone? I.e. don't make your application environmental dependent. – BalusC Nov 26 '10 at 22:18
  • Yes, I was talking about a standalone Java application that runs on the desktop. – craigzooka Nov 27 '10 at 06:19
  • Here is the situation I am trying to avoid. The users of this application are intended to be subscribers to a particular website. This is a financial website that has a subscription fee of about $3,000 a year. My feeling is, they will be much less inclined to use my program if they have to type their username/password into it, as this username/password cost them 3k. So the idea would be to have them log in through normal means(any browser), then my program could somehow get their PHPSESSID cookie and use that to access the site. – craigzooka Nov 27 '10 at 06:24
  • So you want to use their username and password in your program, without them knowing about it? That sounds a lot like account theft to me. If you need credentials, be honest about it to your users. – Jorn Nov 27 '10 at 22:52
  • Jorn, that is not my intention at all. To give you some context, let me tell you exactly what my java application does. I am a member of the same site, www.philstockworld.com. On any given trading day there is a post about that particular day. We currently use the comments under that post as a "live chat". What is unbelievably annoying is the comments are not organized into threads or sorted in any way. They appear in the order they were submitted tagged with the user and time. In addition, we have to keep refreshing the page in order to see if there are any new comments. – craigzooka Nov 27 '10 at 23:16
  • My application is intended to ping the website at whatever refresh rate the user wants and well as grab all the comments so that I can format them in whatever way I want. Ideally you end up interacting with my program instead of hitting refresh on your webbrowser every minute. This also allows me the possibility of coming up with a more intelligent way of viewing the comments, possibly constructing some kind of tree so you can who has replied to whose questions, etc. – craigzooka Nov 27 '10 at 23:19

3 Answers3

2

The location of the Cookies file is:

On Linux:

$HOME/.config/google-chrome/Default/Cookies

For other OS's see the user data page on chromium.org.

However, the file is stored in a binary format, so it's going to be hard for you to load the data within.

Joel
  • 29,538
  • 35
  • 110
  • 138
2

Joel's answer tells you where the cookie data is stored. This data is a sqlite3 database file. See this question for how to read a sqlite3 database.

Community
  • 1
  • 1
moinudin
  • 134,091
  • 45
  • 190
  • 216
0

I can't find how/where Chrome stores cookies, on Linux at least. Chances are that they won't be cached as simple plain text files and thus not be easily readable. You say you don't want to hard code your username/password in your java app - but why do you have do this? You could just pass them as arguments to your app?

Richard H
  • 38,037
  • 37
  • 111
  • 138
  • Passing the username/pass as arguments is still a problem, as the user will have to type those into my program. The whole point of this is so that my Java application never needs to see their username/password. – craigzooka Nov 27 '10 at 06:26