致命错误:无法重新声明connectt()(之前在声明中声明)

时间:2018-06-05 09:10:21

标签: php

我尝试了一些帖子,但没有什么可以解决我的错误,有人可以看到我有错误的地方? 它显示:致命错误:无法重新声明connectt()(之前在

中声明
<?php
$jsonContents = file_get_contents('data/data.json');
$data_array = json_decode($jsonContents, true);
foreach($data_array as $key=> $value) {
    $domain = $value['domain'];
    function connectt($domain, $port, $timeOut = 5)
    {
        $fp = fsockopen($domain, $port, $errno, $errstr, $timeOut);
        if (!$fp) {
            $jsonContents = file_get_contents('data/data.json');
            $data_array = json_decode($jsonContents, true);
            foreach ($data_array as $key => $value) {
                $domain = $value['domain'];
                $data_array = json_decode($jsonContents, true);
                $jsonContents = file_get_contents('data/data.json');
                if ($value['domain'] == $domain) {
                    $data_array[$key]['ssl'] = "Not Valid";
                }
            };
            $json = json_encode($data_array);
            file_put_contents('data/data.json', $json);
        } else {
            $jsonContents = file_get_contents('data/data.json');
            $data_array = json_decode($jsonContents, true);
            foreach ($data_array as $key => $value) {
                $domain = $value['domain'];
                $jsonContents = file_get_contents('data/data.json');
                $data_array = json_decode($jsonContents, true);
                if ($value['domain'] == $domain) {
                    $data_array[$key]['ssl'] = "Valid";
                }
                $json = json_encode($data_array);
                file_put_contents('data/data.json', $json);
            }
        }
    }
    $port = 443;
    connectt($domain, $port);
}

1 个答案:

答案 0 :(得分:1)

请从foreach循环中删除connectt()函数。这是你的最终代码

   <?php
   $jsonContents = file_get_contents('data/data.json');
   $data_array = json_decode($jsonContents, true);

       function connectt($domain, $port, $timeOut = 5)
       {
           $fp = fsockopen($domain, $port, $errno, $errstr, $timeOut);
           if (!$fp) {
               $jsonContents = file_get_contents('data/data.json');
               $data_array = json_decode($jsonContents, true);
               foreach ($data_array as $key => $value) {
                   $domain = $value['domain'];
                   $data_array = json_decode($jsonContents, true);
                   $jsonContents = file_get_contents('data/data.json');
                   if ($value['domain'] == $domain) {
                       $data_array[$key]['ssl'] = "Not Valid";
                   }
               };
               $json = json_encode($data_array);
               file_put_contents('data/data.json', $json);
           } else {
               $jsonContents = file_get_contents('data/data.json');
               $data_array = json_decode($jsonContents, true);
               foreach ($data_array as $key => $value) {
                   $domain = $value['domain'];
                   $jsonContents = file_get_contents('data/data.json');
                   $data_array = json_decode($jsonContents, true);
                   if ($value['domain'] == $domain) {
                       $data_array[$key]['ssl'] = "Valid";
                   }
                   $json = json_encode($data_array);
                   file_put_contents('data/data.json', $json);
               }
           }
       }
   foreach($data_array as $key=> $value) {
       $domain = $value['domain'];
       $port = 443;
       connectt($domain, $port);
   }