A
A
Artur Kosikov2019-12-07 00:29:56
PhantomJS
Artur Kosikov, 2019-12-07 00:29:56

Why doesn't php PhantomJS save cookies?

I'm trying to figure out PHP-PhantomJS ( jonnnnyw.github.io/php-phantomjs )
For the test, I created the following php page:

<?php
session_start();
setcookie('php', '1');
print_r(getallheaders());
?>
<script>
  var cookieString = "js=1";
  document.cookie = cookieString;
</script>

The browser receives 3 cookies here: PHPSESSID, js, php
I visit this page as a Phantom:
<?php
use JonnyW\PhantomJs\Client;
$client = Client::getInstance();
  $client->getEngine()->addOption('--load-images=true');
  $client->getEngine()->addOption( '--ignore-ssl-errors=true' );
  $client->getEngine()->addOption('--ssl-protocol=any');
  $client->getEngine()->addOption('--cookies-file=cookie.txt');
  $client->getEngine()->addOption('--local-storage-path=storage');
  $client->getEngine()->addOption('--web-security=false'); 

        $response = $client->getMessageFactory()->createResponse();
  $client->send( $request, $response );

With $response everything is OK. The cookie.txt is created. Here's what's in it:
[General]
[email protected](\0\0\0\x7f\0\0\0\x16QList<QNetworkCookie>\0\0\0\0\x1\0\0\0\0)

As far as I understand, cookies are not written due to the fact that they are all session cookies.
If you add expires - then the cookies are saved ...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question