我有这段代码,但似乎没有用。在文本字段中输入IP并按下按钮后,它将返回页面加载到PHP代码,但不会加载PHP代码结果,也不会加载任何代码。
<?php
if(isset($_POST['resolve'])){
$api = "https://iphub.p.mashape.com/api.php?ip=";
$endbit = "&showtype=4";
if(strlen($_POST['name'])==0){
echo "fill in all fields!";
} else {
// assuming $_POST['resolve'] has an IP
// $response = file_get_contents($api.$_POST['name'].$endbit);
$response = Unirest\Request::get($api.$_POST['name'].$endbit,
array(
"X-Mashape-Key" => "U3sk6nAZzBmshyiHEUZHigxLGp1ZTZnKjsnkd8LWULJmRRp",
"Accept" => "application/json"
)
);
?>
<div align="center">
<?php
if($response['proxy'] == '0') {
echo 'No';
}
elseif($response['proxy'] == '1') {
echo 'Yes';
}
else {
echo 'Error.';
}
?>
</div>
<?php
}
}
?>
我使用的API要求我有标题/ X-Mashape-Key。