Php curl cookie session to phantomjs


#1

Guys,

i hope you can help me, i created a script via php using cURL to auto login on a site and i can successfully login on the site. Now im using PhantomJS screenshot and im calling it via php exec(). My question is it possible i can pass the cookie/session to phantomjs that i created via PHP curl? The page i need to screenshot needs authentication so im using php CURL to login.

Thanks,

Mike


#2

Hi,

if not cURL what about on actual PhantonJS Code, can we get session cookies and use it, something like this

"use strict";
var page = require('webpage').create(),
	system = require('system'),
	server = 'https://domain.com/login.php',
    data = 'username=myusername&password=password',
    screenshot_url = 'https://domain.com/dashboard.php',
    screenshot = '/Users/myuser/screenshot.png';

page.open(server, 'post', data, function (status) {
	if (status !== 'success') {
        console.log('Unable to post!');
    } else {
    	page.viewportSize = { width: 600, height: 600 };
    	page.open(screenshot_url, function(status) {
    		if (status !== 'success') {
                console.log('Unable to load the address!');
                phantom.exit(1);
            } else {
                window.setTimeout(function () {
                    page.render(screenshot);
                    phantom.exit();
                }, 200);
            }
    	});
    }
    phantom.exit();
} 

Thanks,

Mike