Connect Via Proxy To URL With PHP

Discussion in 'PHP' started by scottmweaver, Feb 11, 2007.

  1. #1
    Hey guys,

    I need software that will use a proxy to connect to a URL.

    I'm not making a proxy browsing script, nor anything illegal. I just need it for testing purposes.

    Anyone know how to do this simply inside of PHP?

    Thanks in advance,
    Scott
     
    scottmweaver, Feb 11, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You can use cURL.

    
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://your-url.com');
    curl_setopt($ch, CURLOPT_PROXY, 'your-proxy-server');
    curl_setopt($ch, /*other options you need */);
    
    PHP:
    www.php.net/curl
     
    nico_swd, Feb 12, 2007 IP
  3. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #3
    If you have no curl, you can use file_get_contents + stream_context_create:

    
    <?
    
    $opts = array('http' => array('proxy' => 'tcp://proxyserver:80', 'request_fulluri' => true));
    $context = stream_context_create($opts);
    
    $s = file_get_contents('http://www.google.com', false, $context);
    
    echo $s;
    ?>
    
    PHP:
     
    wmtips, Feb 12, 2007 IP
    exam likes this.
  4. scottmweaver

    scottmweaver Peon

    Messages:
    1,181
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks a lot guys. I'll test those out. :D
     
    scottmweaver, Feb 12, 2007 IP
  5. timelf123

    timelf123 Peon

    Messages:
    897
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #5
    sorry for the revival, but how can I have that script read a list of proxies? i do not want an array, but rather to read a list of proxies from a txt file
     
    timelf123, Mar 25, 2007 IP
  6. scottmweaver

    scottmweaver Peon

    Messages:
    1,181
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    0
    #6
    
    
    <?php
    
    $proxyfile = "proxies.txt";
    
    $fh = fopen($proxyfile, "r");
    if($fh)
    {
     while(!feof($fh))
     {
       $proxies = fread($fh, filesize($proxies));
     }
     fclose($fh);
    }
    
    print $proxies;
    ?>
    
    
    PHP:
    I think that should do it. Didn't test it though.

    Let me know. :)

    Scott
     
    scottmweaver, Mar 25, 2007 IP
  7. conmavn

    conmavn Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You can pass via proxygate.us
     
    conmavn, Mar 26, 2007 IP