Bear with me as i will try my best to explain the scenario.i have database for my website which contains visitors information.I have been testing this database and website using local Host with different browsers such as Firefox,IE and GoogleCrome. The database works fine as i am saving "time","IP address","browser name" and "country" of the visitor.Now that i have hosted this website on a domain,Database works fine for Firefox,IE..but whenever the website is accessed from GoogleCrome,there is no entry in the database for that.I am using XAMPP SQL database for testing
Here is the code of that
<?php
function get_browser_name($user_agent)
{
if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return
'Opera Browser';
elseif (strpos($user_agent, 'Edge')) return 'Edge';
elseif (strpos($user_agent, 'Chrome')) return 'Google Chrome';
elseif (strpos($user_agent, 'Safari')) return 'Safari';
elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7'))
return 'Internet Explorer';
return 'Other';
}
$agent=get_browser_name($_SERVER['HTTP_USER_AGENT']);
$xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?
ip=".getRealIpAddr());
$user ='root';
$pass ='';
$db ='simplecounter';
$db = new mysqli('localhost', $user, $pass, $db) or die("unable to
connect");
$find_counts = mysqli_query($db,"SELECT * FROM user_count");
$ip=$_SERVER['REMOTE_ADDR'];
$date = new DateTime("now", new DateTimeZone($xml-
>geoplugin_timezone) );
$timee= $date->format('Y-m-d H:i:s');
$sql = "INSERT INTO user_count
(browser_name, ip_address, visiting_time, country)
VALUES ( '.$agent.', '.$ip.', '.$timee.',
'.$xml->geoplugin_countryName.')";
if ($db->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share
internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip
is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
?>
Unable to find the root reason for the problem ,any help would be great.