开发者

getting cookie from an external javascript in php before generating HTML output

开发者 https://www.devze.com 2023-03-23 17:36 出处:网络
Is it possible getting cookie from an external js with Php before generating HTML to the br开发者_JAVA技巧owser?

Is it possible getting cookie from an external js with Php before generating HTML to the br开发者_JAVA技巧owser?

Something like

 <?

     //Get if i have some cookie information
     if($_COOKIE["js_app"])
           $cookie_js = $_COOKIE["js_app"];

     //now, talk with some app.js
     if($cookie_js)
         $cookie = some_function(target = 'some_domanin/app.js',$cookie_js);
     else
         $cookie = some_function(target = 'some_domanin/app.js');

     $_COOKIE["js_app"] = $cookie;

     //now i can generate the HTML output. 

    ....


  ?>


It isn't possible because the javascript would never be executed. Your some_function (assuming it used cURL to make the request and pass along the cookie), would just receive the javascript code (like what happens when you view javascript source in your browser).

When JS is loaded by the browser, the browser's javascript interpreter handles parsing and executing the javascript.

Edit: Hmm... googling for "php javascript interpreter" resulted in http://j4p5.sourceforge.net/index.php. Never used it before and probably never will but if you don't need to interact with the user-side of things, that might help you out.


You are looking for a way to send request with cookies, and get the cookies from the response using PHP, right? I think PEAR HTTP_Request is what you are looking for, although you have to install it on your server as a package.

If that is not an option, I guess you will have to do HTTP requests using sockets.

UPDATE: If you are setting the cookies using Javascript, you will have to parse the javascript - not really an option. These functions only work when the cookies are set server-side.

0

精彩评论

暂无评论...
验证码 换一张
取 消