Difficult PHP Curl and Javascript problem about XHR 🙁
I am doing a project for a company.
and Im kinda stuck at a point, and I dont have much time left.. only 5 days and too much work to do..
My task is to obtain a randomly generated link from a webpage.
but the problem is, that link on that webpage is not visible.
it is generated by javascript and XHR
when the user visits the page, the page automatically calls:
http://remoteserver.com/files/get/?JsHttpRequest=12676538542502-xml
It submits a POST requests to that URL
action=get_link&file_id=10594365&code=355333a1&pass=undefined
Now using Firebug, I discovered that the response from that request looks like this:
{ "id": "12676555281100", "js": { "answer": { "link": "http:\/\/test1.remoteserver.com\/get_file\/%3D%3DgZ9A5Q8%7CcktN-hZDXJTQxOELHxIfNEpeBP3aPpAd-PkDFGQCVVtNVOyJIIy-BVPxo3exCapmEj791m3QEAX9F3XZXwXSOdidubkNRyNPwLNXQ-q4pk1oUtT-uox9k21XWK7OOY9uU-J2lIzjt7JdxdicPSUis02LhdPUquHLx9X0rILVzTqxY9o3rjx%7CszFMEeFPvWkdeLgfEkwpeGAJ42LH6mSYrO1Uj1H2m9Bzw0suhYV%7CYccdTdfynWfKtuc6-gLrfaOExfNc0eqx4nccRR%7CF95uMAwQRofCb6aHZO7iimqLRGAg7V836uuAWk0BdmMDaITaT95aP1OVcSPb1Zh" } }, "text": "" }
But the problem occurs here:
when I try to rePOST the same url with same variables, it gives me this response:
{ "id": "12676555281100", "js": { "error": "Your link has expired.
Please try the link again. " }, "text": "" }
So I guess the server checks for JsHttpRequest=12676538542502-xml first to see if we have the session.. then it gives us response.
But Im not even changing the session, I just replayed the same request on same session, still it gave me that error response.
So I think Ive got to find a way to get the current JsHttpRequest=12676538542502-xml ID , and use it on my URL ..
but the problem is, on the page, it doesnt show any request id or anything.
the only thing I know is that from the server response, the generated link is assigned to a javascript variable : file_link
I tried using this on firefox on the generated link's page : javascript: alert(file_link);
and my assumptions were correct, the variable had the right value..
So what Ive got to do now is, find a way to make PHP+CURL get the value from that javascript variable somehow.. is this possible?? is there any other to do what Im trying to do ?? get the javascript variable's value.
and yes, the file_link is not defined anywhere in the sourcecode, or js included files.
its value is assigned by that XHR
Please help me, I spent a lot of time on this project, and now Im stuck at this point 🙁