编译时我的代码出错:
致命错误:未捕获ArgumentCountError:参数太少 函数getData :: QueryWhoisServer(),传入0 C:\ xampp \ htdocs \ testVisitor \ index.php在第19行,正好是2 预期在C:\ xampp \ htdocs \ testVisitor \ Model \ getData.php:72 Stack trace:#0 C:\ xampp \ htdocs \ testVisitor \ index.php(19): getData-> QueryWhoisServer()#1 {main}引入 第72行的C:\ xampp \ htdocs \ testVisitor \ Model \ getData.php
我知道,因为php 7.0我需要传递参数但参数不能识别......
这是我的代码:
index.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;
}
}
答案 0 :(得分:0)
函数getData :: QueryWhoisServer()的参数太少,0传递给C:\ xampp \ htdocs \ testVisitor \ index.php
$getData->QueryWhoisServer();
没有提供任何参数。
答案 1 :(得分: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
和$domain
(域用于fputs),
这将是:
$getData->QueryWhoisServer($whoisserver, $domain);
同样在你的功能中
LookupIP($domain);
结果使用了功能QueryWhoisServer,因此尝试获取$result