-1

编译时我的代码中有错误:

致命错误:未捕获的 ArgumentCountError:函数 getData::QueryWhoisServer() 的参数太少,第 19 行的 C:\xampp\htdocs\testVisitor\index.php 中传递了 0,而 C:\xampp\htdocs\testVisitor\ 中正好有 2 Model\getData.php:72 堆栈跟踪:#0 C:\xampp\htdocs\testVisitor\index.php(19): getData->QueryWhoisServer() #1 {main} 在 C:\xampp\htdocs\testVisitor\ 中抛出第 72 行的模型\getData.php

我知道从 php 7.0 开始我需要传递参数,但参数无法识别......

这是我的代码:

索引.php:

require_Once('Model/getData.php');
require_Once('Controller/writeData.php');

$getData = new getData();
$writeData =new  writeData();

$getData->get_ip();
$getData->LookupIP($domain);
$getData->ValidateIP($domain);
$getData->QueryWhoisServer();



if($domain && $pageEnCours != preg_match("#localhost/testVisitor/$#",$pageEnCours)) {
    $domain = trim($domain);

    if($getData->ValidateIP($domain)) {
        $result = $getData->LookupIP($domain);
       $writeData->write_domain($result);
    }

    else{
        write_error();
    };

}
echo $domain;
echo "cc";

和 getData.php :

$urlPart1 = $_SERVER['HTTP_HOST'] ;
$urlPart2 =  $_SERVER['REQUEST_URI'];
$pageEnCours = $urlPart1 .= $urlPart2;
$domain ='0.0.0.0';
class getData
{

// For the full list of TLDs/Whois servers see http://www.iana.org/domains/root/db/ and http://www.whois365.com/en/listtld/
    /**
     * Récupérer la véritable adresse IP d'un visiteur
     */
    function get_ip() {
        // IP si internet partagé
        global $domain;
        if (isset($_SERVER['HTTP_CLIENT_IP'])) {
            return $domain =$_SERVER['HTTP_CLIENT_IP'];
        }
        // IP derrière un proxy
        elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            return $domain=$_SERVER['HTTP_X_FORWARDED_FOR'];
        }
        // Sinon : IP normale
        else {
            return $domain=(isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '');
        }
    }

    function LookupIP($ip) {
        $whoisservers = array(
            //"whois.afrinic.net", // Africa - returns timeout error :-(
            //"whois.lacnic.net", // Latin America and Caribbean - returns data for ALL locations worldwide :-)
            //"whois.apnic.net", // Asia/Pacific only
            //"whois.arin.net", // North America only
            //"whois.ripe.net" // Europe, Middle East and Central Asia only
        );
        $results = array();
        foreach($whoisservers as $whoisserver) {
            $result = QueryWhoisServer($whoisserver, $ip);

            if ($result && !in_array($result, $results)) {
                $results[$whoisserver] = $result;
            }

        }
        $res = "RESULTS FOUND: " . count($results);
        foreach($results as $whoisserver=>$result) {
            $res .= "\n\n-------------\nLookup results for " . $ip . " from " . $whoisserver . " server:\n\n" . $result;
        }
        return $res;
    }
    function ValidateIP($ip) {
        $ipnums = explode(".", $ip);
        if(count($ipnums) != 4) {
            return false;
        }
        foreach($ipnums as $ipnum) {
            if(!is_numeric($ipnum) || ($ipnum > 255)) {
                return false;
            }
        }
        return $ip;
    }

    function QueryWhoisServer($whoisserver , $domain ) {
        $port = 43;
        $timeout = 10;
        $fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout) or die("Socket Error " . $errno . " - " . $errstr);
        //if($whoisserver == "whois.verisign-grs.com") $domain = "=".$domain; // whois.verisign-grs.com requires the equals sign ("=") or it returns any result containing the searched string.
        fputs($fp, $domain . "\r\n");
        $out = "";
        while(!feof($fp)){
            $out .= fgets($fp);
        }
        fclose($fp);
        $res = "";
        if((strpos(strtolower($out), "error") === FALSE) && (strpos(strtolower($out), "not allocated") === FALSE)) {
            $rows = explode("\n", $out);
            foreach($rows as $row) {
                $row = trim($row);
                if(($row != '') && ($row{0} != '#') && ($row{0} != '%') && ($row != preg_match("#^netname|^descr|^country|^person|^address|^phone#",$row ))) {
                    $res .= $row."\n";
                }
            }
        }
        return $res;
    }

}
4

2 回答 2

0

在您的功能中:

function QueryWhoisServer($whoisserver , $domain ) {
        $port = 43;
        $timeout = 10;
        $fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout)
        fputs($fp, $domain . "\r\n");

$fp需要$whoisserver$port并且$timeout

和在函数中$port定义$timeout

但是调用这个函数的时候需要指定$whoisserver和(fputs中使用域),$domain

那将是这样的:

$getData->QueryWhoisServer($whoisserver, $domain);

也在你的功能中

LookupIP($domain); 

结果使用函数QueryWhoisServer,所以尝试获取$result

于 2018-06-15T13:03:33.963 回答
0

函数 getData::QueryWhoisServer() 的参数太少,在 C:\xampp\htdocs\testVisitor\index.php 中传递了 0

$getData->QueryWhoisServer();没有提供任何论据。

于 2018-06-15T10:31:55.387 回答