2014-12-30 173 views
-5

任何想法這有什麼不對?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

+0

我想象你在第29行錯過了一個分號,如果它抱怨第30行出現意外的「回聲」。 –

+0

在這一行:'$ data = ...'沒有分號 – Rizier123

+2

對不起,我覺得現在真的很愚蠢。 :S –

回答

1

你的線#28月底錯過一個分號的錯誤:

Parse error: syntax error, unexpected T_ECHO..通常會通知某個行號,但是當它發生時,您應該始終查看到您遇到錯誤的行。

請現在考慮查看幫助 - >遊覽,否則您將被視爲脫離主題。

+0

對不起,沒想過:S我的appologies –

0

它有echo在那裏沒想到一個;您在前面的陳述結尾處忘記了分號。