Fetching cookie?

Hi All,
Kindly suggest for the following issue
Issue:
As we know cookies stored in Mozilla(in Tools> Internet options> privacy

show all cookies).
I am trying to fetch cookies other than localhost, i.e. fetching cookies
created by other websites, using Ruby on Rails.
Kindly help me out…

Thanks in advance,
Saurabh

I am trying to fetch cookies other than localhost, i.e. fetching cookies
created by other websites, using Ruby on Rails.

Need to be a little more specific. What are you trying to do with these
said cookies? Trying to extract the information from them? Copying all
non-localhost cookies somewhere? Deleting non-local cookies?

Explain in what way you want to use the information.

  • Mac

Michael L. wrote:

I am trying to fetch cookies other than localhost, i.e. fetching cookies
created by other websites, using Ruby on Rails.

Need to be a little more specific. What are you trying to do with these
said cookies? Trying to extract the information from them? Copying all
non-localhost cookies somewhere? Deleting non-local cookies?

Explain in what way you want to use the information.

  • Mac

Hi Mac,
Trying to extract the information of non-localhost cookies, like their
name, content; plz suggest something.

Thanks

Saurabh P. wrote:

Michael L. wrote:

I am trying to fetch cookies other than localhost, i.e. fetching cookies
created by other websites, using Ruby on Rails.

Need to be a little more specific. What are you trying to do with these
said cookies? Trying to extract the information from them? Copying all
non-localhost cookies somewhere? Deleting non-local cookies?

Explain in what way you want to use the information.

  • Mac

Hi Mac,
Trying to extract the information of non-localhost cookies, like their
name, content; plz suggest something.

Thanks

I’ll try to explain it by an example
I’m working on Ruby, localhost is my server, i’m trying to fetch the
name and content of cookie created by google or any other non localhost
website. Plz suggest me how shall i go for it.

Thanks

Ok so you might do something like the following:

#Change the directory to where your cookies are located
#As an example I believe windows uses the following directory:

Dir.chdir(“C:/Documents and Settings/username/cookies”) #not positive on
this

cookies = Dir.glob("*.txt")

cookies.each do |file|
info = File.readlines(file)
#here is where you would put the code to manipulate the data
#as you see fit. The name and content is in the info array.

end

Firefox is a bit different however; it stores all the cookie information
in one text file.

So instead of reading each file individually you would open that single
file and use split to organize the data into an array.

Dir.chdir("/home/user/.mozilla/firefox/x08923x.default")
cookies = File.readlines(“cookies.txt”)

Note there are much faster ways of reading a file but this only
usually applies to very large files… File.readlines should be
sufficient for what you’re doing.

Cheers!

  • Mac

Michael L. wrote:

Oh and as far as the non-localhost thing goes, if you store localhost
cookies just use an if statement to filter them out.

if file != “127.0.0.1” || file != “localhost”
#code here
else
end

  • Mac

Thanks Mac,
But still a query, can’t we access cookies by using another path???
Hard disk or the specified path stores a single cookie name of that
website, if more than one cookie names are to be accessed from the same
site?? will u plz suggest me something??

Thanks again,
Saurabh

But still a query, can’t we access cookies by using another path???
Hard disk or the specified path stores a single cookie name of that
website, if more than one cookie names are to be accessed from the same
site??

Explain what you want to do with these cookies after ‘fetching’ them. I
think I am a bit confused as to what your end goal is here.

Regards,

  • Mac

Michael L. wrote:

But still a query, can’t we access cookies by using another path???
Hard disk or the specified path stores a single cookie name of that
website, if more than one cookie names are to be accessed from the same
site??

Explain what you want to do with these cookies after ‘fetching’ them. I
think I am a bit confused as to what your end goal is here.

Regards,

  • Mac

Hi Mac,
The problem is:
The solution which you had provided is working for my PC because i know
the username but the difficult thing is to implement the same ruby code
on another PC whose username is not known, hence i was asking about the
path where username is not required to fetch the cookie. After fetching
i’ll store it in an array and display its name and content.

Thanks for Suggestions,
Saurabh

path where username is not required to fetch the cookie. After fetching
i’ll store it in an array and display its name and content.

Oh ok, that’s easy enough. So if you wanted to change to the cookie
directory say of “C:/Documents and Settings/username/cookies” but
“username” is not pre-defined you could use something like this:

Dir.chdir(“C:/Documents and Settings/#{ENV[‘USERNAME’]}/cookies”)

This would use the account username that the user is currently logged
into.
Naturally, the paths would be different using *nix

Regards,

  • Mac

Michael L. wrote:

path where username is not required to fetch the cookie. After fetching
i’ll store it in an array and display its name and content.

Oh ok, that’s easy enough. So if you wanted to change to the cookie
directory say of “C:/Documents and Settings/username/cookies” but
“username” is not pre-defined you could use something like this:

Dir.chdir(“C:/Documents and Settings/#{ENV[‘USERNAME’]}/cookies”)

This would use the account username that the user is currently logged
into.
Naturally, the paths would be different using *nix

Regards,

  • Mac

Thanks Mac
It works, got the cookie name and content.

Thanks again,
Saurabh

Oh and as far as the non-localhost thing goes, if you store localhost
cookies just use an if statement to filter them out.

if file != “127.0.0.1” || file != “localhost”
#code here
else
end

  • Mac