simplexml_load_file() with proxy server ? how?












-1














I try to implement in php the following code together with using proxies:



$data = simplexml_load_file('http://www.testdomain.com/data/search?q='.
urlencode($searchstring).'&format=xml');


How can i modify this code so that the URL is fetched via a proxy server?
I found some examples, but they all use cURL and i dont exactly know how to implement it.



Any help would be appreciated !



Annotation:
would it work like this?



$url = "http://www.testdomain.com/data/search?q='.urlencode($searchstring).'&format=xml";
$agent = "Mozilla/5.0 (X11; U; Linux i686; en-US)
AppleWebKit/532.4 (KHTML, like Gecko)
Chrome/4.0.233.0 Safari/532.4";

$referer = "http://www.google.com/";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, '202.95.141.129:8080');
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);

$curldata = curl_exec($ch);
curl_close($ch);


$data = simplexml_load_string($curldata);


?










share|improve this question
























  • php.net/simplexml_load_file - there is a stream-context that allows you to specify the proxy server: php.net/libxml_set_streams_context - proxy (and other) stream context options for HTTP: php.net/context.http
    – hakre
    Sep 9 '13 at 22:35


















-1














I try to implement in php the following code together with using proxies:



$data = simplexml_load_file('http://www.testdomain.com/data/search?q='.
urlencode($searchstring).'&format=xml');


How can i modify this code so that the URL is fetched via a proxy server?
I found some examples, but they all use cURL and i dont exactly know how to implement it.



Any help would be appreciated !



Annotation:
would it work like this?



$url = "http://www.testdomain.com/data/search?q='.urlencode($searchstring).'&format=xml";
$agent = "Mozilla/5.0 (X11; U; Linux i686; en-US)
AppleWebKit/532.4 (KHTML, like Gecko)
Chrome/4.0.233.0 Safari/532.4";

$referer = "http://www.google.com/";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, '202.95.141.129:8080');
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);

$curldata = curl_exec($ch);
curl_close($ch);


$data = simplexml_load_string($curldata);


?










share|improve this question
























  • php.net/simplexml_load_file - there is a stream-context that allows you to specify the proxy server: php.net/libxml_set_streams_context - proxy (and other) stream context options for HTTP: php.net/context.http
    – hakre
    Sep 9 '13 at 22:35
















-1












-1








-1


1





I try to implement in php the following code together with using proxies:



$data = simplexml_load_file('http://www.testdomain.com/data/search?q='.
urlencode($searchstring).'&format=xml');


How can i modify this code so that the URL is fetched via a proxy server?
I found some examples, but they all use cURL and i dont exactly know how to implement it.



Any help would be appreciated !



Annotation:
would it work like this?



$url = "http://www.testdomain.com/data/search?q='.urlencode($searchstring).'&format=xml";
$agent = "Mozilla/5.0 (X11; U; Linux i686; en-US)
AppleWebKit/532.4 (KHTML, like Gecko)
Chrome/4.0.233.0 Safari/532.4";

$referer = "http://www.google.com/";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, '202.95.141.129:8080');
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);

$curldata = curl_exec($ch);
curl_close($ch);


$data = simplexml_load_string($curldata);


?










share|improve this question















I try to implement in php the following code together with using proxies:



$data = simplexml_load_file('http://www.testdomain.com/data/search?q='.
urlencode($searchstring).'&format=xml');


How can i modify this code so that the URL is fetched via a proxy server?
I found some examples, but they all use cURL and i dont exactly know how to implement it.



Any help would be appreciated !



Annotation:
would it work like this?



$url = "http://www.testdomain.com/data/search?q='.urlencode($searchstring).'&format=xml";
$agent = "Mozilla/5.0 (X11; U; Linux i686; en-US)
AppleWebKit/532.4 (KHTML, like Gecko)
Chrome/4.0.233.0 Safari/532.4";

$referer = "http://www.google.com/";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, '202.95.141.129:8080');
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);

$curldata = curl_exec($ch);
curl_close($ch);


$data = simplexml_load_string($curldata);


?







php curl proxy simplexml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 6 '13 at 9:29

























asked Sep 6 '13 at 9:01









user2753657

53




53












  • php.net/simplexml_load_file - there is a stream-context that allows you to specify the proxy server: php.net/libxml_set_streams_context - proxy (and other) stream context options for HTTP: php.net/context.http
    – hakre
    Sep 9 '13 at 22:35




















  • php.net/simplexml_load_file - there is a stream-context that allows you to specify the proxy server: php.net/libxml_set_streams_context - proxy (and other) stream context options for HTTP: php.net/context.http
    – hakre
    Sep 9 '13 at 22:35


















php.net/simplexml_load_file - there is a stream-context that allows you to specify the proxy server: php.net/libxml_set_streams_context - proxy (and other) stream context options for HTTP: php.net/context.http
– hakre
Sep 9 '13 at 22:35






php.net/simplexml_load_file - there is a stream-context that allows you to specify the proxy server: php.net/libxml_set_streams_context - proxy (and other) stream context options for HTTP: php.net/context.http
– hakre
Sep 9 '13 at 22:35














2 Answers
2






active

oldest

votes


















2














Get the file via cURL and load the content in simplexml_load_string.






share|improve this answer





















  • thanks! i changed my original post - would it work like in my example?
    – user2753657
    Sep 6 '13 at 9:36






  • 1




    Excepting the typo error in line 1, it should. Haven't you tested it?
    – secelite
    Sep 6 '13 at 9:45












  • sorry, cant test it on this computer right now, have to wait till tonight... what typo?
    – user2753657
    Sep 6 '13 at 10:00










  • Okay. First Line: $url = "http://www.testdomain.com/data/search?q=".urlencode($searchstring)."&format=xml"; instead of $url = "http://www.testdomain.com/data/search?q='.urlencode($searchstring).'&format=xml";
    – secelite
    Sep 6 '13 at 12:57





















0














This is some sample code. It work for me:



$context = array(
'http' => array(
'proxy' => 'proxy.domain:3128',
'request_fulluri' => true,
),
);
$cxContext = stream_context_create($context);
$sFile = file_get_contents("http://static.cricinfo.com/rss/livescores.xml", False, $cxContext);
$xml = simplexml_load_string ( $sFile."" );





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18653865%2fsimplexml-load-file-with-proxy-server-how%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Get the file via cURL and load the content in simplexml_load_string.






    share|improve this answer





















    • thanks! i changed my original post - would it work like in my example?
      – user2753657
      Sep 6 '13 at 9:36






    • 1




      Excepting the typo error in line 1, it should. Haven't you tested it?
      – secelite
      Sep 6 '13 at 9:45












    • sorry, cant test it on this computer right now, have to wait till tonight... what typo?
      – user2753657
      Sep 6 '13 at 10:00










    • Okay. First Line: $url = "http://www.testdomain.com/data/search?q=".urlencode($searchstring)."&format=xml"; instead of $url = "http://www.testdomain.com/data/search?q='.urlencode($searchstring).'&format=xml";
      – secelite
      Sep 6 '13 at 12:57


















    2














    Get the file via cURL and load the content in simplexml_load_string.






    share|improve this answer





















    • thanks! i changed my original post - would it work like in my example?
      – user2753657
      Sep 6 '13 at 9:36






    • 1




      Excepting the typo error in line 1, it should. Haven't you tested it?
      – secelite
      Sep 6 '13 at 9:45












    • sorry, cant test it on this computer right now, have to wait till tonight... what typo?
      – user2753657
      Sep 6 '13 at 10:00










    • Okay. First Line: $url = "http://www.testdomain.com/data/search?q=".urlencode($searchstring)."&format=xml"; instead of $url = "http://www.testdomain.com/data/search?q='.urlencode($searchstring).'&format=xml";
      – secelite
      Sep 6 '13 at 12:57
















    2












    2








    2






    Get the file via cURL and load the content in simplexml_load_string.






    share|improve this answer












    Get the file via cURL and load the content in simplexml_load_string.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Sep 6 '13 at 9:03









    secelite

    1,26911118




    1,26911118












    • thanks! i changed my original post - would it work like in my example?
      – user2753657
      Sep 6 '13 at 9:36






    • 1




      Excepting the typo error in line 1, it should. Haven't you tested it?
      – secelite
      Sep 6 '13 at 9:45












    • sorry, cant test it on this computer right now, have to wait till tonight... what typo?
      – user2753657
      Sep 6 '13 at 10:00










    • Okay. First Line: $url = "http://www.testdomain.com/data/search?q=".urlencode($searchstring)."&format=xml"; instead of $url = "http://www.testdomain.com/data/search?q='.urlencode($searchstring).'&format=xml";
      – secelite
      Sep 6 '13 at 12:57




















    • thanks! i changed my original post - would it work like in my example?
      – user2753657
      Sep 6 '13 at 9:36






    • 1




      Excepting the typo error in line 1, it should. Haven't you tested it?
      – secelite
      Sep 6 '13 at 9:45












    • sorry, cant test it on this computer right now, have to wait till tonight... what typo?
      – user2753657
      Sep 6 '13 at 10:00










    • Okay. First Line: $url = "http://www.testdomain.com/data/search?q=".urlencode($searchstring)."&format=xml"; instead of $url = "http://www.testdomain.com/data/search?q='.urlencode($searchstring).'&format=xml";
      – secelite
      Sep 6 '13 at 12:57


















    thanks! i changed my original post - would it work like in my example?
    – user2753657
    Sep 6 '13 at 9:36




    thanks! i changed my original post - would it work like in my example?
    – user2753657
    Sep 6 '13 at 9:36




    1




    1




    Excepting the typo error in line 1, it should. Haven't you tested it?
    – secelite
    Sep 6 '13 at 9:45






    Excepting the typo error in line 1, it should. Haven't you tested it?
    – secelite
    Sep 6 '13 at 9:45














    sorry, cant test it on this computer right now, have to wait till tonight... what typo?
    – user2753657
    Sep 6 '13 at 10:00




    sorry, cant test it on this computer right now, have to wait till tonight... what typo?
    – user2753657
    Sep 6 '13 at 10:00












    Okay. First Line: $url = "http://www.testdomain.com/data/search?q=".urlencode($searchstring)."&format=xml"; instead of $url = "http://www.testdomain.com/data/search?q='.urlencode($searchstring).'&format=xml";
    – secelite
    Sep 6 '13 at 12:57






    Okay. First Line: $url = "http://www.testdomain.com/data/search?q=".urlencode($searchstring)."&format=xml"; instead of $url = "http://www.testdomain.com/data/search?q='.urlencode($searchstring).'&format=xml";
    – secelite
    Sep 6 '13 at 12:57















    0














    This is some sample code. It work for me:



    $context = array(
    'http' => array(
    'proxy' => 'proxy.domain:3128',
    'request_fulluri' => true,
    ),
    );
    $cxContext = stream_context_create($context);
    $sFile = file_get_contents("http://static.cricinfo.com/rss/livescores.xml", False, $cxContext);
    $xml = simplexml_load_string ( $sFile."" );





    share|improve this answer




























      0














      This is some sample code. It work for me:



      $context = array(
      'http' => array(
      'proxy' => 'proxy.domain:3128',
      'request_fulluri' => true,
      ),
      );
      $cxContext = stream_context_create($context);
      $sFile = file_get_contents("http://static.cricinfo.com/rss/livescores.xml", False, $cxContext);
      $xml = simplexml_load_string ( $sFile."" );





      share|improve this answer


























        0












        0








        0






        This is some sample code. It work for me:



        $context = array(
        'http' => array(
        'proxy' => 'proxy.domain:3128',
        'request_fulluri' => true,
        ),
        );
        $cxContext = stream_context_create($context);
        $sFile = file_get_contents("http://static.cricinfo.com/rss/livescores.xml", False, $cxContext);
        $xml = simplexml_load_string ( $sFile."" );





        share|improve this answer














        This is some sample code. It work for me:



        $context = array(
        'http' => array(
        'proxy' => 'proxy.domain:3128',
        'request_fulluri' => true,
        ),
        );
        $cxContext = stream_context_create($context);
        $sFile = file_get_contents("http://static.cricinfo.com/rss/livescores.xml", False, $cxContext);
        $xml = simplexml_load_string ( $sFile."" );






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 '18 at 9:28









        Rbar

        1,01111234




        1,01111234










        answered Nov 20 '18 at 9:08









        Vu Phan

        1




        1






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18653865%2fsimplexml-load-file-with-proxy-server-how%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?