0

I'm trying to pass cookies from PHP to the rendered webpage.

My configuration is:

$config = array(

            "logLevel"=> \LogLevel::DEBUG,
            "javaScriptMode" => \JavaScriptMode::ENABLED_REAL_TIME,
            "enableDebugMode" => true,
            "cookies" => array(
                array(
                    "key" => "sid",
                    "value" => "abc"
                ),
                array(
                    "key" => "soid",
                    "value" => "def"
                )
            )
        );

But when I try to access the cookies via document.cookie, the property is empty.

Any suggestions?

  • I don't know anything about PDF Reactor, sorry. Do the backslashes in `"logLevel"=> \LogLevel::DEBUG,` and `"javaScriptMode" => \JavaScriptMode::ENABLED_REAL_TIME,` need to be there? – user1801810 Dec 14 '16 at 18:08
  • 2
    I'm voting to close this question as off-topic because this is addressed to "Real Objects team" and not the Stackoverflow community. It belongs in whatever communication channel "Real Objects team" has for support. – Quentin Dec 15 '16 at 14:56
  • Basically same post as a year ago from OP - https://stackoverflow.com/questions/34198135/set-cookies-in-configuration-using-php – user1801810 Dec 15 '16 at 16:43
  • Dear user1801810, my question is a bit different this time. I can pass cookies to PHP, but not the webpage itself. But my question has been answered down in this thread. – S. Schwaiger Dec 15 '16 at 19:25
  • Btw., the backslahes are required because the code is embedding in a custom namespace. – S. Schwaiger Dec 15 '16 at 19:25

1 Answers1

0

Cookies that are specified in the configuration are automatically send by PDFreactor each time it opens a HTTP or HTTPS connection to e.g. request resources or perform AJAX calls in JavaScript. They currently are not added to the "document.cookie" property.

Do you have any specific use case for this or are you simply trying to make data from your PHP integration accessible in the document's JavaScript during conversion? In the latter case, you could add a user script to your configuration that includes the cookie data like this:

$config = array(
    // ...
    "userScripts" => array(
        array(
            "content" => "var myCookies = { sid: 'abc', soid: 'def' }",
            "beforeDocumentScripts" => true
        )
    )
);

You can now access the cookies from within JavaScript via the "myCookies" property.

realobjects
  • 301
  • 1
  • 5
  • Currently I store custom data in the cookies which is used in a second request. PDFreactor currently only serves the second request. – S. Schwaiger Dec 15 '16 at 19:59
  • Currently I store custom data in the cookies which is used in a second request. PDFreactor currently only serves the second request. With your hint, I just set the JavaScript cookies: "userScripts" => array( array( "content" => 'document.cookie = "soid='.$session->getID().';"', "beforeDocumentScripts" => true ) ) Now I have the problem that PDFreactor does no longer respond - but this a subject to maybe another question. – S. Schwaiger Dec 15 '16 at 20:00