You can see what Ajax requests are happening through Firebug, not to mention all the variables that are getting passed and the responses.
Hello Thanks for reply. Where can I see Ajax requests through Firebug? and variables as well? I searched but without results. I have also logged in. Now I am at members area where I have a software version number and download button. I need to check the version number and then press download button with some method of PHP. While I am thinking, maybe someone will have some ideas. I will post the code of members area to paste2.org. How do I extract the version and how to make my script download it after? http: / /pa ste2. org/p/926802 I guess the variables I need are in the script but I have no idea how to extract it.
Also, the CURL stops on AJAX styled page, which says loading. But only a few seconds later loads a normal page. How do I make my script to load not the Loading ajax page, but normal one? However, anyway, it still has the code I gave, so I wont be able to extract it properly...
Ok, I looked in Firebug for headers/responses, it seem to be unable to download some files because they are located on other server. So it tried for example, to download localhost:8080/members/image.jpg but I need it to go to softwarewebpage.com/members/image.jpg... Maybe that would do the trick?
Any idea what the version information string should consist of? Unable, so the files are on another server which appears to be offline?
Firebug shows it's in caption tags, with 3 number(format x.x.x), it also says before version number : Latest version No, the server is not offline, The problem is that it tries to download those images from my computer, but not from the actual software server.
I also found out that in response it posts some server.php script which has some code in it to post all captions, where all versions, file names are etc When I try to get it's contents : Warning: file_get_contents(webpage/scripts/server.php) [function.file-get-contents]: failed to open stream: HTTP request failed!
I found out that it POSTS to server some parameters, and in responce gets the page content. Can I deliver those parameters with the help of CURL?
Sure you can <?php $ch = curl_init("http://location.us/pageToPost.php"); curl_setopt($ch, CURLOPT_POSTFIELDS, "data to post"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $reply = curl_exec($ch); curl_close($ch); ?> PHP: Reply from the POST action will be stored in $reply variable. You can then echo it and do whatever you want with it.
Hey, thanks! But, the data it sends has some characters PHP does not want to see. Here is example : {"C":"Gpf_Rpc_Server", "M":"run", "requests":[{"C":"Gpf_Rpc_Server", "M":"syncTime", "offset":"36000000"},{"C":"Gpf_Templates_TemplateService", "M":"getTemplate", "templateName":"main"},{"C":"Gpf_Templates_TemplateService", "M":"getTemplate", "templateName":"menu"},{"C":"Dp_Ui_MyProducts", "M":"getWidget"}], "S":"5daee5e838d04a7df7e0ed2880baa2fe"} Code (markup): Firebug also shows some Source parameters, I am not sure they are needed(?). In exchange for this, a page is loaded with full content I need.
The example code you provided seems to have all characters. And as for extracting, I recommend using regular expressions. In order to extract 5daee5e838d04a7df7e0ed2880baa2fe, do the following preg_match('!"S":"([a-z0-9]+?)"!',$reply,$match); // Tested pattern PHP: Then you can access the session ID (I guess it is one) by doing $match[1], for example: echo $match[1]; // Outputs: 5daee5e838d04a7df7e0ed2880baa2fe echo $match[0]; // Outputs: "S":"5daee5e838d04a7df7e0ed2880baa2fe" because that's the whole matched pattern PHP:
Thank you, but, how do I put the code i provided to a variable? I need to send this code to a script on a server so that it will return content to me. In order to parse the code I need to put it into variable, but PHP does not allow to put those things like "" :, into variables, it gives me back error.
You can use single-quotes instead of double-quotes. So it would be $variable = ' {"C":"Gpf_Rpc_Server", "M":"run", "requests":[{"C":"Gpf_Rpc_Server", "M":"syncTime", "offset":"36000000"},{"C":"Gpf_Templates_TemplateService", "M":"getTemplate", "templateName":"main"},{"C":"Gpf_Templates_TemplateService", "M":"getTemplate", "templateName":"menu"},{"C":"Dp_Ui_MyProducts", "M":"getWidget"}], "S":"5daee5e838d04a7df7e0ed2880baa2fe"}'; PHP: Since there are only double-quotes in the code, single-quotes should be just fine around it. Then just do <?php $ch = curl_init("http://location.us/pageToPost.php"); curl_setopt($ch, CURLOPT_POSTFIELDS, $variable); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $reply = curl_exec($ch); curl_close($ch); ?> PHP:
Hmm, I tried it but I guess the idea is not working, since the script does not return content to me... Something is wrong because probably S is always random parameters...
Then you have to get the updated S every time you do the post query. Also, did you echo $reply; or not? Did you view the source code after that (Ctrl+U in most browsers)? Maybe the response was in XML so it's displayed in source only. (Chrome does it that way)
Hello, Yes, I echoed, no result. Also, I thought that cURL would probably always show me only Loading and I would not be able to get contents from source code? Or I can get contents from source code aswell? The head is cracking from all this.
You actually can only get the source code. The "Loading" part is how client's browser parses the code, but cURL can't do JavaScript. So $reply is the source code of the page you can work on with.
However, I have no responce from the server, echoing $reply does not help... I know DOM selection of source helps(my webdesigner plugin shows all dom source, what I actually need), but I don't know how to do this with PHP..
Finally, SOLVED! I should have put D=$variable because the parameter name was D and now it shows me full HTML. Another problems arose : I need to preg_match_all the page for "Latest version" keyword, but when I echo the results put in array, it replies only : Undefined offset : 0,1 and so on. How do I parse the page for my keywords to get results to an array? It also some times say that delimiter cannot be alphanumeric or backslash...
Ok, I have sorted this out, but it gives me back only a match. I need to get the content located between some HTML code... For example, between <caption> tags... How do i do that? I am using this code, but in return it just says : Array. If I put print_r($match); instead of last line I get : There are 2 places where <caption> </caption< are, but why do I get no data inside array?