J
J
jistulamle2018-03-14 11:49:25
PHP
jistulamle, 2018-03-14 11:49:25

Why is the if condition not processed correctly?

There are following functions:

//  Проверка доступности сайта через прокси
function checkProxy($proxy = null)
{
  if (!empty($proxy)) {

    //	Заголовок запроса
      Curl::sampleCurl()->addHttpheaders([
          "User-Agent"      => 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0', 
          "Accept"          => "application/json, text/javascript, */*; q=0.01", 
          "Accept"          => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 
          "Accept-Language" => "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3"
          ]);

      //	Подстановка прокси в запрос
      Curl::sampleCurl()->setProxy($proxy);


      $response = Curl::sampleCurl()->post('https://site.com');
      if (preg_match('/ih" value="(\w+)/', $response)) {
          return true;
      }
  }
}

function newProxy($i = 0)
{
    $proxy_list = getProxy();	//	getProxy() получает список прокси в виде ip:port
    while ($i < sizeof($proxy_list)) {

    	//	Проверка работоспособности прокси и отсутствие дубликата
        if (checkProxy($proxy_list[$i]) && !DataBase::Db()->checkRow('SELECT count(proxy) FROM ' . Config::DB_TABLE . ' WHERE proxy="' . $proxy_list[$i] . '"')) {
            $proxy = $proxy_list[$i];
            break;
        }
    ++$i;    
    }
    if (!empty($proxy)) return $proxy;
}

if I call like this:
if (!checkProxy('179.24.4.164:8080')) {
   echo 'Новая прокся:  ' . newProxy() . '<br />';
}

issued:
5aa8df68ba1e4837278387.png
if you just call: ip is issued normally: It seems that everything has been painted, is it clear what's the catch?
echo 'Новая прокся: ' . newProxy() . '<br />';
5aa8e0107e3ce682660128.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander null, 2018-03-14
@snikes

add at the end of the checkProxy function
return false;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question