Bueno les dejo una clase en la que aún estoy trabajando ( para ampliara ) es parte de un proyecto en el que trabajo, la comparto pues de esta web he aprendido mucho y es mi forma de decirles
gracias y porque creo en el
software libre
Código PHP:
Ver original<?php
/*
*
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
class Get_data_vistor{
// atributos
private $frowarded_for;
private $http_via;
private $remote_addr;
private $browser=array(); private $user_agent_conv_lang;
private $user_agent_conv_so;
private $user_agent_conv_browser;
function __construct() {
// tomo la ip filtrando proxie
$this->frowarded_for=isset($_SERVER['HTTP_X_FORWARDED_FOR']); $this->http_via=(isset($_SERVER['HTTP_VIA'])); $this->remote_addr=(isset($_SERVER['REMOTE_ADDR'])); // constructores de lenguage
$this->lang[0]="es";
$this->lang[1]="en";
$this->lang[2]="fr";
// constructores de so
$this->so[0]="linux";
$this->so[1]="windows";
// constructores de browser
$this->browser[0]="mozilla";
$this->browser[1]="explorer";
$this->browser[2]="chrome";
// convierto a minúsculas
$this->user_agent_conv_lang=strtolower($_SERVER[HTTP_ACCEPT_LANGUAGE
]); $this->user_agent_conv_so=strtolower($_SERVER[HTTP_USER_AGENT
]); $this->user_agent_conv_browser=strtolower($_SERVER[HTTP_USER_AGENT
]); }
// metodos
public function get_ip_v(){
if ($this->frowarded_for) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}elseif ($this->http_via) {
$ip = $_SERVER['HTTP_VIA'];
}elseif ($this->remote_addr) {
$ip = $_SERVER['REMOTE_ADDR'];
}
echo $ip;
return $ip;
}// End function get_ip()
public function get_lang_v(){
if (@strpos($this->user_agent_conv_lang, $this->lang[0]) !== false){ $lang= "Español";
}
if (@strpos($this->user_agent_conv_lang, $this->lang[1]) !== false){ $lang= "Ingles";
}
echo $lang;
return $lang;
}
public function get_so_v(){
if (@strpos($this->user_agent_conv_so, $this->so[0]) !== false){ $so= "linux";
}
if (@strpos($this->user_agent_conv_so, $this->so[1]) !== false){ $so= "windows";
}
echo $so;
return $so;
}// end functionget_so_v
public function get_browsrer_v(){
// verifico que se encuentre el nombre del explorador en la
// variable con strpos
if(strpos($this->user_agent_conv_browser, $this->browser[0]) !==false){ $browser="mozilla";
}
if(strpos($this->user_agent_conv_browser, $this->browser[1]) !==false){ $browser="explorer";
}
if(strpos($this->user_agent_conv_browser, $this->browser[2]) !==false){ $browser="chrome";
}
if(strpos($this->user_agent_conv_browser,"opera") !==false){ $browser="opera";
}
if(strpos($this->user_agent_conv_browser,"mirodi") !==false){ $browser="mirodi";
}
echo $browser;
return $browser;
} // end function get_browser_v
public function up_mail_data_v(){
$ip= $this->get_ip_v();
$so= $this->get_so_v();
$lang= $this->get_lang_v();
$browser= $this->get_browsrer_v();
// Varios destinatarios
// subject
$titulo = 'data visitor';
// message
$mensaje = '
<html>
<head>
<title>datos del visitante</title>
</head>
<body>
<p>¡Estos son los datos tomados del visitante</p>
<table>
<tr>
<th>SO</th><th>Navegador</th><th>IP</th><th>lenguage</th>
</tr>
<tr>
<td>'.$so.'</td><td>'.$browser.'</td><td>'.$ip.'</td><td>'.$lang.'</td>
</tr>
<tr>
</tr>
</table>
</body>
</html>';
// Almaceno el la BBDD los datos
$server='xxx';
$username='xxx';
$password='xxx';
$db='data';
$sql="INSERT INTO visitante ";
$sql .="(id,ip,so,lang,browser,date)";
$sql .="VALUES ('NULL','$ip','$so','$lang','$browser','$date ')";
if (!$res) {
die("ATENCION!!! No fue posible insertar datos:<br />".mysql_error()); }
// Envio el mail co el reporte del visitante
// Para enviar un correo HTML mail, la cabecera Content-type debe fijarse
$cabeceras = 'MIME-Version: 1.0' . "\r\n";
$cabeceras .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Cabeceras adicionales opcionales comentadas
mail($para, $titulo, $mensaje, $cabeceras); }
function __destruct() {
unset ($browser ,$lang, $so ,$ip); }
}// end calss get_data_visitor
echo 'class get_data_visitor <br />';
$t=new Get_data_vistor();
$t->get_lang_v();
echo '<br />';
$t->get_so_v();
echo '<br />';
$t->get_browsrer_v();
echo '<br />';
$t->get_ip_v();
$t->up_mail_data_v();
?>