script that enable to connect to a specific url using proxy server

Discussion in 'Programming' started by web.business, Jun 17, 2011.

  1. #1
    with this script you can connect to any website using proxy server:
    and it can be used as alternative way for using: file(),file_get_contents(),fopen(),simpleXMLElement(),...
    to connect to a specific url , if these functions are disabled on the host server ,
    or you have to use proxy to reach an url.
    the function fetch_content() return the url as sting so you can handle it as you like,
    and i just output it in this script. enjoy it
    <form action="digitalpoint_1.php" method="post">
    <input type="text" name="url" value="Enter your url here" size="50" >
    <input type="text" name="url_proxy" value="Enter your url proxy here" size="50">
    <input type="text" name="port_proxy" value="Enter your proxy  port here" size="50">
    <input type="submit" value="Connect">
    </form>
    HTML:
    <?php
    function fetch_content($URL,$url_proxy,$port_proxy) {
    $ch = curl_init();
    
    	curl_setopt ( $ch, CURLOPT_URL, $URL );
    curl_setopt($ch, CURLOPT_HEADER, 0);
    
    curl_setopt($ch, CURLOPT_PROXY, $url_proxy);
    curl_setopt($ch, CURLOPT_PROXYPORT, $port_proxy);
    	curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
    
    $data=curl_exec($ch);
    
    return $data;	
    
     curl_close($ch);
    }
    echo fetch_content($_POST["url"],$_POST["url_proxy"],$_POST["port_proxy"]);
    
    ?>
    PHP:

     
    web.business, Jun 17, 2011 IP
  2. SiJz

    SiJz Peon

    Messages:
    51
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I use this method a lot - it works really well.
     
    SiJz, Jun 21, 2011 IP
  3. seowikiliks

    seowikiliks Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    case 'HTTP':
                   
     curl_setopt($cUrl, CURLOPT_PROXY, $Proxy); 
    curl_setopt($cUrl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
    PHP:
    case 'Socks4':
                   
     curl_setopt($cUrl, CURLOPT_PROXY, $Proxy); 
    curl_setopt($cUrl, CURLOPT_PROXYTYPE, 4);
     
    PHP:
    case 'Socks5':
                 
    curl_setopt($cUrl, CURLOPT_PROXY, $Proxy); 
    curl_setopt($cUrl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
    PHP:
     
    seowikiliks, Jun 22, 2011 IP