[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Fetching cookie???

Saurabh Peshkar

3/14/2009 4:33:00 AM

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
--
Posted via http://www.ruby-....

10 Answers

Michael Linfield

3/14/2009 5:42:00 AM

0

> 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
--
Posted via http://www.ruby-....

Saurabh Peshkar

3/14/2009 7:13:00 AM

0

Michael Linfield 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
--
Posted via http://www.ruby-....

Saurabh Peshkar

3/14/2009 8:26:00 AM

0

Saurabh Peshkar wrote:
> Michael Linfield 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
--
Posted via http://www.ruby-....

Michael Linfield

3/14/2009 8:48:00 PM

0

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

--
Posted via http://www.ruby-....

Michael Linfield

3/14/2009 8:52:00 PM

0

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
--
Posted via http://www.ruby-....

Saurabh Peshkar

3/16/2009 12:44:00 PM

0

Michael Linfield 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
--
Posted via http://www.ruby-....

Michael Linfield

3/16/2009 11:47:00 PM

0

> 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

--
Posted via http://www.ruby-....

Saurabh Peshkar

3/17/2009 5:37:00 AM

0

Michael Linfield 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
--
Posted via http://www.ruby-....

Michael Linfield

3/17/2009 7:37:00 AM

0

> 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

--
Posted via http://www.ruby-....

Saurabh Peshkar

3/17/2009 10:26:00 AM

0

Michael Linfield 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
--
Posted via http://www.ruby-....