Set cookies in configuration using PHP

191 Views Asked by At

I'd like to print a document with PDFreactor using PHP.

Unfortunately, the document generation fails when specifying cookies in the configuration. Leaving out the cookies line prints our login page - with is correct as the page displays a login screen if no session cookie could be identified.

$config = array(
    "document"=> "http://localhost",
    "logLevel"=> LogLevel::DEBUG,
    "javaScriptMode" => JavaScriptMode::ENABLED_TIME_LAPSE,
    "enableDebugMode" => true,
    "cookies" => array("sid" => "abcdefghijklmno")//<-- problematic line
);

Could anybody verify that cookie passing fails with PHP or give advice about the correct syntax?

1

There are 1 best solutions below

0
On BEST ANSWER

The issue is caused by a mistake in the syntax of your cookie configuration. The correct syntax would be:

$config = array(    
    "document"=> "http://localhost",
    "logLevel"=> LogLevel::DEBUG,
    "javaScriptMode" => JavaScriptMode::ENABLED_TIME_LAPSE,
    "enableDebugMode" => true,    
    "cookies" => array(
        array("key" => "sid", "value" => "abcdefghijklmno") // <-- corrected
    )
);

For multiple cookies:

"cookies" => array(
    array("key" => "cookiename1", "value" => "cookievalue1"),
    array("key" => "cookiename2", "value" => "cookievalue2")
)