Código PHP:
Ver original
<?php /* * * * Copyright 2010 Mauricio Rodriguez <[email protected]> * * 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 $user_agent_conv_lang; private $user_agent_conv_so; private $user_agent_conv_browser; function __construct() { // tomo la ip filtrando proxie // 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 } // 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(){ $lang= "Español"; } $lang= "Ingles"; } echo $lang; return $lang; } public function get_so_v(){ $so= "linux"; } $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 $browser="mozilla"; } $browser="explorer"; } $browser="chrome"; } $browser="opera"; } $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) { } // 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 //$cabeceras .= 'To: xxxx <[email protected]>, xxxx <[email protected]>' . "\r\n"; //$cabeceras .= 'Cc: [email protected]' . "\r\n"; } function __destruct() { } }// 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(); ?>