D
D
Danil Sysoev2016-09-15 00:54:03
PHP
Danil Sysoev, 2016-09-15 00:54:03

How to properly implement cURL with proxy?

Guys, welcome. In general, the situation is as follows. There is a service - mine, through which users pass authorization on a third-party resource. The administrator of this resource, quarreled that everything is from one IP, multi-acc and so on. I suggested to him that I would work through a proxy, and he kindly agreed. Now I'm trying to implement all this. I thought it would be easier, but I ran into the following difficulties:
1) At first I tried to rob the proxy, it worked out in part - but once every other time, and if it works, then slowly. Places 504 causes though timeouts stand. Regularly made a check, he sees the site or not. Etc.
2) I thought, but oh well, I'll buy a proxy subscription. I inserted 50 proxies, ate everything from them - and did not even show it on one site. Generally excellent. (Regular season works, checked)
So, where to get proxies for such purposes, what do you need? How are they implemented? People parse tons of pages, and I need a little. About 400-700 authorizations per day at first. And authorized ones are already in cookies for a month, but not about that.
Please guide the lost one.
This is the script I'm trying to access:

function post_sp($url, $post, $refer, $us, $auth = 1){

  global $CONNECT;

  $ch_proxy = mysqli_fetch_assoc(mysqli_query($CONNECT, "SELECT * FROM `users` WHERE `login` = '$us'"));
  $ch_proxy = $ch_proxy['proxy'];

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36");
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  curl_setopt($ch, CURLOPT_REFERER, $refer);
  curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie/sp/".$us.".txt");
  curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie/sp/".$us.".txt");


  while ( $auth == 0 ) {

      $filename= 'resource/proxy/proxy.php';
      $txt = file($filename);
      $txt2 = array_slice($txt, 0, 1);
      $txt3 = implode('', $txt2);
      file_put_contents($filename, array_slice($txt, 1));
      $proxy_auth = $txt2[0];

      curl_setopt($ch, CURLOPT_PROXY, $proxy_auth);
      curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
      curl_setopt($ch, CURLOPT_TIMEOUT, 9);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 6);

      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      $result  = curl_exec($ch);
      preg_match('/регулярка/', $result, $res);

      if ( $res[0] == 'регулярка' ) {
        $auth = 1;
        mysqli_query($CONNECT, "UPDATE `users` SET proxy='$proxy_auth' WHERE login='$us'");
        $ch_proxy = mysqli_fetch_assoc(mysqli_query($CONNECT, "SELECT * FROM `users` WHERE `login` = '$us'"));
        $ch_proxy = $ch_proxy['proxy'];
      } else {
        mysqli_query($CONNECT, "UPDATE `users` SET proxy='' WHERE login='$us'");
        $ch_proxy = mysqli_fetch_assoc(mysqli_query($CONNECT, "SELECT * FROM `users` WHERE `login` = '$us'"));
        $ch_proxy = $ch_proxy['proxy'];
      }

  }
  curl_close($ch);
  return $result;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Inter Carpenter, 2016-09-15
@Byrger

For these tasks, I buy VPS for 100-200r
. I place a simple php script on them with a curl request to the site I need, and it takes the necessary variables from above.
And with my site I already apply via curl to the script that lies on the vps.
You can also buy a stack of IP addresses from many VPS hostings.
That is, 1 VPS is installed and 10-100 IPs are bought

D
Danil Sysoev, 2016-09-15
@YoungOldMan

Suddenly someone will face something like this. In general, I found a solution to the problem in the Tor network.
However, I note that it is not suitable for all purposes.
https://habrahabr.ru/sandbox/38998/
phpforum.su/index.php?showtopic=83831
Everything is detailed here. However, I still can't force the IP to change.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question