Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/10/2010, 18:41
Avatar de mcun
mcun
 
Fecha de Ingreso: octubre-2010
Ubicación: tras la pantalla
Mensajes: 466
Antigüedad: 13 años, 6 meses
Puntos: 55
Mensaje [APORTE]toma los datos del visitante (ip navegador lenguaje so )

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
  1. <?php
  2. /*
  3.  *
  4.  *
  5.  *      Copyright 2010 Mauricio Rodriguez <[email protected]>
  6.  *
  7.  *      This program is free software; you can redistribute it and/or modify
  8.  *      it under the terms of the GNU General Public License as published by
  9.  *      the Free Software Foundation; either version 2 of the License, or
  10.  *      (at your option) any later version.
  11.  *
  12.  *      This program is distributed in the hope that it will be useful,
  13.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *      GNU General Public License for more details.
  16.  *
  17.  *      You should have received a copy of the GNU General Public License
  18.  *      along with this program; if not, write to the Free Software
  19.  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20.  *      MA 02110-1301, USA.
  21.  */
  22.  
  23. class Get_data_vistor{
  24.     // atributos
  25.     private $frowarded_for;
  26.     private $http_via;
  27.     private $remote_addr;
  28.     private $lang=array();
  29.     private $so=array();
  30.     private $browser=array();
  31.     private $user_agent_conv_lang;
  32.     private $user_agent_conv_so;
  33.     private $user_agent_conv_browser;
  34.     function  __construct() {
  35.         // tomo la ip filtrando proxie
  36.         $this->frowarded_for=isset($_SERVER['HTTP_X_FORWARDED_FOR']);
  37.         $this->http_via=(isset($_SERVER['HTTP_VIA']));
  38.         $this->remote_addr=(isset($_SERVER['REMOTE_ADDR']));
  39.         // constructores de lenguage
  40.         $this->lang[0]="es";
  41.         $this->lang[1]="en";
  42.         $this->lang[2]="fr";
  43.         // constructores de so
  44.         $this->so[0]="linux";
  45.         $this->so[1]="windows";
  46.         // constructores de browser
  47.         $this->browser[0]="mozilla";
  48.         $this->browser[1]="explorer";
  49.         $this->browser[2]="chrome";
  50.         // convierto a minúsculas
  51.         $this->user_agent_conv_lang=strtolower($_SERVER[HTTP_ACCEPT_LANGUAGE]);
  52.         $this->user_agent_conv_so=strtolower($_SERVER[HTTP_USER_AGENT]);
  53.         $this->user_agent_conv_browser=strtolower($_SERVER[HTTP_USER_AGENT]);
  54.         }
  55.             // metodos
  56.     public  function get_ip_v(){
  57.         if ($this->frowarded_for) {
  58.             $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  59.         }elseif ($this->http_via)  {
  60.             $ip = $_SERVER['HTTP_VIA'];
  61.         }elseif ($this->remote_addr) {
  62.             $ip = $_SERVER['REMOTE_ADDR'];
  63.         }
  64.         echo $ip;
  65.         return $ip;
  66.     }// End function get_ip()
  67.         public function get_lang_v(){
  68.             if (@strpos($this->user_agent_conv_lang, $this->lang[0]) !== false){
  69.                 $lang= "Espa&ntilde;ol";
  70.             }
  71.             if (@strpos($this->user_agent_conv_lang, $this->lang[1]) !== false){
  72.                 $lang= "Ingles";
  73.             }
  74.             echo $lang;
  75.             return $lang;
  76.         }
  77.         public function get_so_v(){
  78.             if (@strpos($this->user_agent_conv_so, $this->so[0]) !== false){
  79.                 $so= "linux";
  80.             }
  81.             if (@strpos($this->user_agent_conv_so, $this->so[1]) !== false){
  82.                 $so= "windows";
  83.             }
  84.             echo $so;
  85.             return $so;
  86.         }// end functionget_so_v
  87.         public function get_browsrer_v(){
  88.         // verifico que se encuentre el nombre del explorador en la
  89.         // variable con strpos
  90.         if(strpos($this->user_agent_conv_browser, $this->browser[0]) !==false){
  91.             $browser="mozilla";
  92.         }
  93.         if(strpos($this->user_agent_conv_browser, $this->browser[1]) !==false){
  94.             $browser="explorer";
  95.         }
  96.  
  97.         if(strpos($this->user_agent_conv_browser, $this->browser[2]) !==false){
  98.             $browser="chrome";
  99.         }
  100.         if(strpos($this->user_agent_conv_browser,"opera") !==false){
  101.             $browser="opera";
  102.         }
  103.         if(strpos($this->user_agent_conv_browser,"mirodi") !==false){
  104.             $browser="mirodi";
  105.         }
  106.         echo $browser;
  107.         return $browser;
  108.     } // end function get_browser_v
  109.     public function up_mail_data_v(){
  110.         $ip=  $this->get_ip_v();
  111.         $so=  $this->get_so_v();
  112.         $lang=  $this->get_lang_v();
  113.         $browser=  $this->get_browsrer_v();
  114.         // Varios destinatarios
  115.         $para  = '[email protected]';
  116.         // subject
  117.         $titulo = 'data visitor';
  118.         // message
  119.         $mensaje = '
  120.        <html>
  121.            <head>
  122.                <title>datos del visitante</title>
  123.            </head>
  124.            <body>
  125.                <p>¡Estos son los datos tomados del visitante</p>
  126.                <table>
  127.                    <tr>
  128.                       <th>SO</th><th>Navegador</th><th>IP</th><th>lenguage</th>
  129.                    </tr>
  130.                    <tr>
  131.                       <td>'.$so.'</td><td>'.$browser.'</td><td>'.$ip.'</td><td>'.$lang.'</td>
  132.                    </tr>
  133.                    <tr>
  134.                    </tr>
  135.                </table>
  136.             </body>
  137.        </html>';
  138.         // Almaceno el la BBDD los datos
  139.         $date = date("Y-m-d");
  140.         $server='xxx';
  141.         $username='xxx';
  142.         $password='xxx';
  143.         $db='data';
  144.         $con=mysql_connect($server, $username, $password);
  145.         mysql_select_db($db, $con);
  146.         $sql="INSERT INTO visitante ";
  147.         $sql .="(id,ip,so,lang,browser,date)";
  148.         $sql .="VALUES ('NULL','$ip','$so','$lang','$browser','$date ')";
  149.         $res = mysql_query($sql,$con);
  150.     if (!$res) {
  151.         die("ATENCION!!! No fue posible insertar datos:<br />".mysql_error());
  152.     }
  153.         // Envio el mail co el reporte del visitante
  154.         // Para enviar un correo HTML mail, la cabecera Content-type debe fijarse
  155.         $cabeceras  = 'MIME-Version: 1.0' . "\r\n";
  156.         $cabeceras .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  157.         // Cabeceras adicionales opcionales comentadas
  158.         //$cabeceras .= 'To: xxxx <[email protected]>, xxxx <[email protected]>' . "\r\n";
  159.         $cabeceras .= 'From: Recordatorio <[email protected]>' . "\r\n";
  160.         //$cabeceras .= 'Cc: [email protected]' . "\r\n";
  161.         mail($para, $titulo, $mensaje, $cabeceras);
  162.         }
  163.     function  __destruct() {
  164.         unset ($browser ,$lang, $so ,$ip);
  165.     }
  166.  
  167. }// end calss get_data_visitor
  168. echo 'class get_data_visitor <br />';
  169. $t=new Get_data_vistor();
  170. $t->get_lang_v();
  171. echo '<br />';
  172. $t->get_so_v();
  173. echo '<br />';
  174. $t->get_browsrer_v();
  175. echo '<br />';
  176. $t->get_ip_v();
  177. $t->up_mail_data_v();
  178. ?>