晚上好,
我正在创建一个脚本来检查代理。但是,我对PHP中的循环有一点了解,我会尽我最大的努力。
代码如下:
<?php
//$_POST INFORMATIONS
$address = $_POST['address'];
if (!empty($_POST['address']))
{
//COMPTE LE NOMBRE D'ENTREES
$delimiter = $address;
$delimiterArray = ($delimiter != '')?explode(",",$delimiter):NULL;
$arrayCount = count($delimiterArray);
for ($i = 1; $i <= $arrayCount; $i++) {
$url = 'http://api.proxyipchecker.com/pchk.php';
//DELIMITE L'IP ET PORT
$format = explode(":", $address);
$ip = $format[0];
$port = $format[1];
//CURL
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,'ip='.$ip.'&port='.$port);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
list($res_time, $speed, $country, $type) = explode(';', curl_exec($ch));
//REMPLACE LE RESULT
if (isset($type))
{
if ($type >= 4 or $type <= 0)
{
$type = "Undefined";
}
elseif ($type = 1)
{
$type = "Transparent";
}
elseif ($type = 2)
{
$type = "Anonymous";
}
elseif ($type = 3)
{
$type = "High anonymous";
}
}
//ECHO RESULT
echo $ip.":".$port." / Response time: ".$res_time." seconds / Country ".$country." / Type ".$type."\n";
}
}错误在这里
//DELIMITE L'IP ET PORT
$format = explode(":", $address);
$ip = $format[0];
$port = $format[1];由于它是一个循环put,1它对第一个是好的,然后它将是一个偏移量。如果任何人有一个想法,非常感谢!
信息:格式-> IP:端口,IP:端口..
我需要为cURL的每个地址的IP和端口。
谢谢你!
发布于 2019-03-07 10:50:08
分解你正在尝试做的事情,你的循环逻辑有点离谱,对于你想要的(我认为)来说太复杂了。
..。
//COMPTE LE NOMBRE D'ENTREES
//THIS IS THE FULL STRING (IP:PORT,IP:PORT,...)
$delimiter = $address;
//THIS IS AN ARRAY OF FORM 0 => "IP:PORT", 1 => "IP:PORT", etc.
$delimiterArray = ($delimiter != '')?explode(",",$delimiter):NULL;
//ARRAYS ARE ITERABLE; USE FOREACH TO TRAVERSE EACH ENTRY
foreach ($delimiterArray as $value){
$value = explode(":", $value);
//THE COPY INSIDE OF VALUE IS NOW AN ARRAY;
//$value[0] IS THE IP
//$value[1] IS THE PORT
//NOW DO WHAT YOU WANT WITH THOSE VALUES
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,'ip='.$value[0].'&port='.$value[1]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
list($res_time, $speed, $country, $type) = explode(';', curl_exec($ch));
//REMPLACE LE RESULT
if (isset($type))
{
if ($type >= 4 or $type <= 0)
{
$type = "Undefined";
}
elseif ($type = 1)
{
$type = "Transparent";
}
elseif ($type = 2)
{
$type = "Anonymous";
}
elseif ($type = 3)
{
$type = "High anonymous";
}
}//end foreach您可能还想在完成后关闭每个curl会话(curl_close)
https://stackoverflow.com/questions/55034942
复制相似问题