PHP - 这有什么问题?
任何想法这有什么不对?PHP - 这有什么问题?
<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
你的线#28月底错过一个分号的错误:
Parse error: syntax error, unexpected T_ECHO..
通常会通知某个行号,但是当它发生时,您应该始终查看行到您遇到错误的行。
请现在考虑查看帮助 - >游览,否则您将被视为脱离主题。
对不起,没想过:S我的appologies –
它有echo
在那里没想到一个;您在前面的陈述结尾处忘记了分号。
没有分号“;”行末28
- Line with starting => $ data =“”。 $ ip。 ...
顺便说一下使用这个类:
$data = "<h1>". $ip . "</h1>"...
这种: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
我正在使用maxmind.com获取ip相关的数据库信息。它是开源的。 – EngineerCoder
我想象你在第29行错过了一个分号,如果它抱怨第30行出现意外的“回声”。 –
在这一行:'$ data = ...'没有分号 – Rizier123
对不起,我觉得现在真的很愚蠢。 :S –