Set cookies in configuration using PHP

青春壹個敷衍的年華 提交于 2019-12-10 17:16:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!