知道这有什么问题吗?
<h1>IP Logger</h1>
<?php
$file = 'ip/index.php';
$date = date('d/m/y');
$time = date('H:i:s');
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$log = '<a href="'. $ip . '">'. $ip . ' </a><br>';
$infofileloc = 'ip/' . $ip . '/index.php';
$infofile = 'Nothing here yet!';
$details = json_decode(file_get_contents("http://ipinfo.io/' . $ip . '/json"));
$city = $details->city;
$hostname = $details->hostname;
$region = $details->region;
$country = $details->country;
$loc = $details->loc;
$org = $details->org;
$data = "<h1>". $ip . "</h1><br>Date: " . $date . "<br>Time: " . $time . "<br>Hostname: " . $hostname . "<br>City: " . $city . "<br>Country: " . $country . "<br>Region: " . $region . "<br>Location: " . $loc . "<br>ISP Org: " . $org . "<br>"
echo("Writing IP to log...<br>");
file_put_contents($file, $log);
echo("Done.<br>");
echo("Writing information file to log...<br>");
if (!file_exists('ip/' . $ip)) {
mkdir('ip/'. $ip, 0777, true) or die("ERROR: Unable to create info directory in /ip/!<br>");
}
file_put_contents("ip/" . $ip . "/index.php", $data);
echo("Done.<br>");
echo($ip . "<br>");
?>
<br>
<a href="ip">Access Logs</a>
我刚收到此错误:
Parse error: syntax error, unexpected T_ECHO in /home/u142114406/public_html/i/index.php on line 30
有什么想法吗? :S
我不知道这里有什么问题,我认为这与最后一个file_put_contents有关,但我不确定。
谢谢, -Connor
答案 0 :(得分:1)
你错过了第28行末尾的分号:
$data = "<h1>". $ip . "</h1>"...
这种错误:
Parse error: syntax error, unexpected T_ECHO..
通常会通知某个行号,但是当它发生时,您应该始终查看 PRIOR 行到您收到错误的行。
现在请考虑查看帮助 - &gt;否则你会被认为是偏离主题的。
答案 1 :(得分:0)
它有一个echo
,它不期待一个;你在前一个陈述的末尾忘记了分号。
答案 2 :(得分:0)
没有分号“;”第28行结束
请使用此课程:http://www.phpclasses.org/package/5680-PHP-Get-geographic-location-of-a-given-IP-address.html
或
http://community.sitepoint.com/t/simple-ip-logging-script/4042