hello. can somebody please find the bug in this programme and fix this ?

Discussion in 'Programming' started by webknowledge, Jun 9, 2014.

  1. #1
    hello. i am not getting the webpage loaded using proxy. can some one please find the bug in it.


    $proxies = array(); // Declaring an array to store the proxy list
    $url = "http://www.quora.com";

    // Adding list of proxies to the $proxies array
    $proxies[] = '109.73.70.165:5005'; // Some proxies require IP and port number
    $proxies[] = '198.148.112.46:7808';

    // Choose a random proxy
    if (isset($proxies)) { // If the $proxies array contains items, then
    $proxy = $proxies[array_rand($proxies)]; // Select a random proxy from the array and assign to $proxy variable
    }

    $ch = curl_init(); // Initialise a cURL handle

    // Setting proxy option for cURL
    if (isset($proxy)) { // If the $proxy variable is set, then
    curl_setopt($ch, CURLOPT_PROXY, $proxy); // Set CURLOPT_PROXY with proxy in $proxy variable
    }

    // Set any other cURL options that are required

    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_URL, $url);

    $results = curl_exec($ch); // Execute a cURL request
    curl_close($ch); // Closing the cURL handle
     
    webknowledge, Jun 9, 2014 IP
  2. Nei

    Nei Well-Known Member

    Messages:
    106
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    170
    #2
    This code works fine (with proxy 198.148.112.46:7808).

    Maybe you forgot line
    echo $results;
    at the end
     
    Nei, Jun 9, 2014 IP
  3. webknowledge

    webknowledge Member

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #3
    nope mate its not working. its still coming blank.
     
    webknowledge, Jun 9, 2014 IP
  4. Nei

    Nei Well-Known Member

    Messages:
    106
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    170
    #4
    then check availability of the curl library on the server
     
    Nei, Jun 9, 2014 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    The easiest way to search for errors is to output variables every time the code changes.
    Do a var_dump($variable)
     
    PoPSiCLe, Jun 9, 2014 IP
  6. YoGem

    YoGem Active Member

    Messages:
    676
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    90
    #6
    Can you access SSH and try to query CURL via command line? Have you tried with curl_error()? http://us2.php.net/curl_error
    Have you tried with curl_setopt($ch, CURLOPT_VERBOSE, true);

    There are many ways to debug CURL!
     
    YoGem, Jun 9, 2014 IP
  7. YoGem

    YoGem Active Member

    Messages:
    676
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    90
    #7
    The first proxy is not working, the second one yes. Transform your proxy array in a variable with just the second proxy. More details below:

    Proxy 109.73.70.165:5005 is not able to open a single site, I used the second one via Terminal and it worked for me.

    ~$ curl -x 198.148.112.46:7808 "http://www.quora.com" --verbose
    * Rebuilt URL to: http://www.quora.com/
    * Hostname was NOT found in DNS cache
    * Trying 198.148.112.46...
    * Connected to 198.148.112.46 (198.148.112.46) port 7808 (#0)
    > GET http://www.quora.com/ HTTP/1.1
    > User-Agent: curl/7.35.0
    > Host: www.quora.com
    > Accept: */*
    > Proxy-Connection: Keep-Alive
    >
    < HTTP/1.1 200 OK
    < Content-Type: text/html; charset=utf-8
    < Date: Mon, 09 Jun 2014 20:36:18 GMT
    < Set-Cookie: m-b="oB46SqyELAVqiTmefkBSag\075\075"; Domain=.quora.com; Max-Age=675919361; Path=/; expires=Fri, 09-Nov-2035 23:59:00 GMT; HttpOnly
    < Set-Cookie: m-s="-Jx_kYOE4koS5cl4SkVxJA\075\075"; Domain=.quora.com; Path=/; HttpOnly
    < Expires: Fri, 01 Jan 1990 00:00:00 GMT
    < X-Frame-Options: SAMEORIGIN
    < Cache-Control: private, no-store, max-age=0, no-cache, must-revalidate, post-check=0, pre-check=0
    < X-UA-Compatible: IE=Edge, chrome=1
    * Server PasteWSGIServer/0.5 Python/2.7.2 is not blacklisted
    < Server: PasteWSGIServer/0.5 Python/2.7.2
    < Pragma: no-cache
    < X-Instart-Request-ID: 7666410320286160481:YNK01-NPPRY09:1402346178:34
    < X-Cache: MISS from CacheServer
    < X-Cache-Lookup: MISS from CacheServer:3127
    < Transfer-Encoding: chunked
    < Via: 1.1 CacheServer (squid/3.2.13)
    < Connection: keep-alive
     
    YoGem, Jun 9, 2014 IP