save and restore cookies

Ask questions here, report about problems.
Post Reply
kojon
Posts: 15
Joined: Mon Mar 25, 2019 7:53 pm

save and restore cookies

Post by kojon » Thu Oct 10, 2019 7:47 pm

How to save and restore a cookies correctly?
$browser->get_cookie(); - I understand saves all cookies for the current page?
$browser->set_cookie() how does it work?

Is it possible to save flash cookies and get session cookies?

KimmoFrye
Posts: 5
Joined: Tue Oct 01, 2019 9:16 pm

Re: save and restore cookies

Post by KimmoFrye » Thu Oct 10, 2019 9:47 pm

I join the question

User avatar
support
Site Admin
Posts: 210
Joined: Fri Feb 22, 2019 3:42 pm

Re: save and restore cookies

Post by support » Fri Oct 11, 2019 12:07 am

To work with cookies the program has the following functions:
  • get_cookie - get cookies for the current page
  • get_cookie_for_url - get cookies for a given url
  • set_cookie - set cookies for the current page
  • set_cookie_for_url - set cookies for a given url
  • flash_cookies_save - save flash cookies
  • flash_cookies_restore - restore flash cookies
  • flash_cookies_delete - delete flash cookies
  • get_cookies_folder – get a folder for the cookies
  • set_cookies_folder – set a folder for the cookies
There are two ways to save and restore different cookies. For example we need save a cookie for two accounts of google.

1. The function browser->set_cookies_folder.

Set cookies folder for "account 1". for example: "cookies/google1/".

Code: Select all

$browser->set_cookies_folder("cookies/google1/");
Then navigate to google and login to account 1 and then close google page.

Next step: change cookies folder for "account 2". for example: "cookies/google2/".

Code: Select all

$browser->set_cookies_folder("cookies/google2/");
Then navigate to google and login to "account 2" and then close google page.

Now when we need using "account 1", we set cookies folder "cookies/google1/" and then navigate to google. If we need using "account 2", we set cookies folder "cookies/google1/" and then navigate to google.

2. The save cookie to file.

Navigate to google and login to "account 1" and then save cookie to file:

$google1 = $browser->get_cookie();
$textfile->write_file("cookies/google1.txt",$google1);


Now same doing for "account 2". Navigate to google and login to "account 2" and then save cookie to file:

Code: Select all

$google2 = $browser->get_cookie();
$textfile->write_file("cookies/google2.txt",$google2);
For restore cookies using follow code:

for "account 1"

Code: Select all

$google1=$textfile->read_file("cookies/google1.txt");
$browser->set_cookie($google1);
// and then
$browser->navigate("http://www.google.com/")

for "account 2"

Code: Select all

$google2=$textfile->read_file("cookies/google2.txt");
$browser->set_cookie($google2);
// and then
$browser->navigate("http://www.google.com/")

Post Reply