-1

I am running Phantomjs, Casperjs with php-casperjs

I want that the login persist on a website, I don't want to have to login every time I start casper.

Now I tried with many sites, I enabled cookies and tested, they works and are the same with different session.

But still the login doesn't persist.

I tried do use disk-cache true. Nothing change.

The Casper UserAgents, viewPortWidth/height doesn't change. The IP is the same. So a fingerprint authentication should still work...

What it is missing?

Edit: some code:

// Casper constructor and setting:

    private $_userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36';
    private $_viewPortWidth = 1345;
    private $_viewPortHeight = 749;
    private $_temp_dir = '/tmp';
    private $_path2casper = '/usr/local/bin/'; //path to CasperJS

//

    $this->casper->setOptions(array(
        'ignore-ssl-errors' => 'yes',
        'ssl-protocol' => 'any',
        'cookies-file' => sys_get_temp_dir().'/JScookies.txt',
        'load-images' => 'true',
        'disk-cache' => 'true'
    ));

// Login

    $this->casper->start($this->LINK_LOGIN);

    $this->casper->waitForSelector('input#btnLogin', 3000);
    $this->casper->fillForm(
        'form[action="/accedi"]',
        array(
            'Username' => $this->Account,
            'Password' => $this->Password
        ), true);
    $this->casper->wait(1000);

    $this->casper->run();
    if($this->CheckLogin($this->casper->getCurrentPageContent()))
        echo "<br> <b>Login Success</b>";
    else
        echo "<br> <b>Error Login</b>";

// test after login

    $this->casper->start($this->LINK_MAIN_PAGE);

    $this->casper->wait(2000);
    $this->casper->run();

    if($this->CheckLogin($this->casper->getCurrentPageContent()))
        echo "<br> <b>Login Success</b>";
    else
        echo "<br> <b>Error Login</b>";
Apoleo
  • 2,045
  • 2
  • 21
  • 37
  • Seems like you are logging in every time, have you tried to check if you're logged in first, then log in? – Vaviloff Nov 01 '16 at 16:36
  • yes, this is just example code – Apoleo Nov 01 '16 at 16:39
  • I cannot resolve this problem. The coockie work fine, but I don't stay logged when i return to sites. When I check the IP with an external page, it return to me an IPv6 It is possible that this is the problem? How can I set to use an IPv4? – Apoleo Nov 25 '16 at 15:40
  • I think the IP issue deserves its own question. – Vaviloff Nov 27 '16 at 05:12

1 Answers1

0

You need to keep cookies on your side:

$casper->setOptions(array(
    'ignore-ssl-errors' => 'yes',
    'cookies-file' => 'cookies.txt'
));
Vaviloff
  • 16,282
  • 6
  • 48
  • 56
  • As I written, I already kept the cookies, and they work fine. But it seems not enough for keep me logged in. – Apoleo Oct 31 '16 at 17:45
  • Are you able to log in to any other established site and keep session there? Say, Twitter or Facebook? If you are, then the problem is in your target site. If not, then the problem might be in your code after all and you need to show a minimal working example here. – Vaviloff Nov 01 '16 at 03:46
  • Thanks for the replies, added some code. I tested the cookies with http://www.whatarecookies.com/cookietest.asp And it remembers my last visited. So cookies should work just fine. I tried with other site like Amazon, they just don't remember me... I think it is the new fingerprint authentication but... – Apoleo Nov 01 '16 at 14:45