I made a simple php, geolocation, but it has a however, I want it: when the guy accesses the site without searching ip none appears the default ip as it is already, but if he accesses and boats in the area of ip search certain ip and it click on search, it will search such ip, and do not know how to do this. If you can help me, thank you.
Follow the code below. I know the code has a lot of gambiarra but after I tidy, the important thing is to be functional.
<title>PEGADOR DE IP</title>
<head>
<style>
body{
background-color: #34495e;
}
body {
color: fff;
}
.startcheck{
background-color: #55C34D;
border: none;
resize: none;
outline: none;
width: 250px;
height: 25px;
color: white;
}
.listcc{
width: 300px;
height: 40px;
background-color: #353C3E;
border: none;
outline: none;
resize: none;
color: white;
text-align: center;
}
#dados {
width: 400px;
margin: 0 auto;
border: 1px solid #000;
text-align: center;
}
#dados ul {
margin: 0;
padding: 0;
list-style: none;
}
#dados ul li {
padding: 5px 5px;
}
#dados p {
text-align: center;
}
</style>
</head>
<br>
<center><input type="text" class="listcc" class="text" placeholder="PESQUISAR IP"></center>
<br>
<center><input type="submit" value="PESQUISAR" class="startcheck"></center><br><br><br>
<?php
header("Content-type: text/html; charset=utf-8"); //Seta o padrão como utf-8
error_reporting(0); //Bloqueia o sistema de mostrar algum erro inutil
//Inicio Vars
$user_ip = getenv('REMOTE_ADDR'); //Vai Puxar o ip do usuario
$geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip")); //Entra no site e puxa os dados
$city = $geo["geoplugin_city"]; //Vai puxar a cidade
$region = $geo["geoplugin_regionName"]; //Vai puxar o estado
$country = $geo["geoplugin_countryName"]; //Vai puxar o país
$browser =$_SERVER['HTTP_USER_AGENT']; //Vai puxar o navegador
date_default_timezone_set('America/Sao_Paulo'); //Vai definir a hora padrão de São paulo - America
$data =date("Y-m-d"); //Vai puxar a data
$hora =date("H:i:s"); //Vai puxar a hora
$useragent = $_SERVER['HTTP_USER_AGENT']; //Vai puxar o navegador utilizado
if (preg_match('|MSIE ([0-9].[0-9]{1,2})|',$useragent,$matched)) {
$browser_version=$matched[1];
$browser = 'IE';
} elseif (preg_match( '|Opera/([0-9].[0-9]{1,2})|',$useragent,$matched)) {
$browser_version=$matched[1];
$browser = 'Opera';
} elseif(preg_match('|Firefox/([0-9\.]+)|',$useragent,$matched)) {
$browser_version=$matched[1];
$browser = 'Firefox';
} elseif(preg_match('|Chrome/([0-9\.]+)|',$useragent,$matched)) {
$browser_version=$matched[1];
$browser = 'Chrome';
} elseif(preg_match('|Safari/([0-9\.]+)|',$useragent,$matched)) {
$browser_version=$matched[1];
$browser = 'Safari';
} else {
// browser not recognized!
$browser_version = 0;
$browser= 'other';
}
//Fim Vars
?>
<div id="dados">
<ul>
<li>IP: <?php echo $user_ip; ?></li>
<li>CIDADE: <?php echo $city; ?></li>
<li>ESTADO: <?php echo $region; ?></li>
<li>PAÍS: <?php echo $country; ?></li>
<li>NAVEGADOR: <?php echo $browser; ?></li>
<li>DATA: <?php echo $data; ?></li>
<li>HORA: <?php echo $hora; ?></li>