问题
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:
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")
)
来源:https://stackoverflow.com/questions/34198135/set-cookies-in-configuration-using-php