1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Urgent : cURL problems

Discussion in 'PHP' started by RxDx, Jul 24, 2010.

  1. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #21
    You can see what Ajax requests are happening through Firebug, not to mention all the variables that are getting passed and the responses.
    SEMrush
     
    Deacalion, Jul 24, 2010 IP
    SEMrush
  2. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #22
    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.
     
    RxDx, Jul 24, 2010 IP
  3. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #23
    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...
     
    RxDx, Jul 24, 2010 IP
  4. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #24
    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?
     
    RxDx, Jul 24, 2010 IP
  5. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #25
    Any idea what the version information string should consist of?
    Unable, so the files are on another server which appears to be offline?
     
    iAreCow, Jul 24, 2010 IP
  6. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #26
    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.
     
    RxDx, Jul 24, 2010 IP
  7. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #27
    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!
     
    RxDx, Jul 25, 2010 IP
  8. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #28
    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?
     
    RxDx, Jul 25, 2010 IP
  9. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #29
    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.
     
    iAreCow, Jul 25, 2010 IP
  10. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #30
    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.
     
    RxDx, Jul 25, 2010 IP
  11. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #31
    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:
     
    iAreCow, Jul 25, 2010 IP
  12. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #32
    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.
     
    RxDx, Jul 25, 2010 IP
  13. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #33
    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:
     
    iAreCow, Jul 25, 2010 IP
  14. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #34
    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...
     
    RxDx, Jul 25, 2010 IP
  15. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #35
    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)
     
    iAreCow, Jul 26, 2010 IP
  16. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #36
    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.
     
    RxDx, Jul 26, 2010 IP
  17. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #37
    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.
     
    iAreCow, Jul 26, 2010 IP
  18. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #38
    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..
     
    RxDx, Jul 26, 2010 IP
  19. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #39
    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...
     
    Last edited: Jul 26, 2010
    RxDx, Jul 26, 2010 IP
  20. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #40
    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?
     
    Last edited: Jul 26, 2010
    RxDx, Jul 26, 2010 IP