I am updating IP location in database using third party free service by a small php script. It was working fine but suddenly it stopped working. I tried to figure out what happened but I could not. Here is my script
<?
$sno = 0;
$query = "SELECT date,ac_no,ip,country FROM visitors where $mainfilter order by ac_no,date desc limit 0,$maximumips;";
$result = db_query($query," ");
while($line=db_fetch_array($result))
{
$country = "";
$updatestatus = "";
$ip = $line[ip];
$sno = $sno + 1;
if($updateip=="Yes")
{
$ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));
if($ip_data && $ip_data->geoplugin_countryName != null)
{
$country = $ip_data->geoplugin_countryName;
}
if($country!="")
{
$q_det = "update visitors set country='$country' where ip='$line[ip]'";
db_exec($q_det);
$q_det = "update ips set country='$country' where ip='$line[ip]'";
db_exec($q_det);
$updatestatus = "Yes - External";
} else {
$updatestatus = "No Trace";
}
sleep($waitseconds);
}
echo "$sno | $line[date] | $line[ac_no] | $ip | $country | $updatestatus";?><br><?
}
?>
The problem is following command $ip = $line[ip];
In cpanel errorlog it says "Use of undefined constant ip - assumed 'ip' in /home/"
However when I use "echo $ip" it prints the ip, it means ip is stored in this variable but on other side it gives above mention error in cpanel.
Earlier I was using $line[ip] variable directly to get country name in following command and it was working perfectly but suddenly it stopped.
$ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$line[ip]));
Then I thought to store IP in $ip variable and then use there but still it does not work.
Please help me to know why cpanel givers error and script stopd although it was working fine and also data is stored in $ip variable which shows when "echo $ip" is used.
Thanks for help