PHP Curl Proxy Server

Gepostet am November 30, 2013

Folgend möchte ich zeigen, wie man einen Curl-Aufruf über einen Proxy realisiert.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function curlConnect($url,$proxyIp='',$proxyPort='',$timeout=20) {
    $curlConnect = curl_init();
    curl_setopt($curlConnect, CURLOPT_HEADER, 0); // Get the header
    curl_setopt($curlConnect, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection
    curl_setopt($curlConnect, CURLOPT_COOKIE, session_name().'='.session_id());
    curl_setopt($curlConnect, CURLOPT_COOKIEJAR, '/tmp');
    curl_setopt($curlConnect, CURLOPT_COOKIESESSION, true);
    curl_setopt($curlConnect, CURLOPT_URL, $url);
    curl_setopt($curlConnect, CURLOPT_RETURNTRANSFER, 1); //gib ausgabe zurück und erzeugt keine Ausgabe
 
    if (!empty($proxyIp) && !empty($proxyPort)) {
        curl_setopt($curlConnect, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
        curl_setopt($curlConnect, CURLOPT_PROXY, $proxyIp.':'.$proxyPort);    
        curl_setopt($curlConnect, CURLOPT_PROXYPORT, $proxyPort);    
        #curl_setopt($curlConnect, CURLOPT_PROXYUSERPWD, 'DOMÄNE\benutzer:password'); 
    }
 
    curl_setopt($curlConnect, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($curlConnect, CURLOPT_CONNECTTIMEOUT, $timeout);
    $useragent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0";
    curl_setopt($curlConnect, CURLOPT_USERAGENT, $useragent);
    #curl_setopt($ch, CURLOPT_REFERER, 'http://myreferer.de');
    
    $curlData = curl_exec($curlConnect);
    #echo $baseurl = curl_getinfo($curlConnect, CURLINFO_EFFECTIVE_URL); exit; //gibt weiterleitung aus
    
    curl_close($curlConnect);
    return $curlData;
}

Tags: ,

Leave a Reply

 

Posts of Current Category



Facebook: