Jump to content

Comment voir les adresses IP de tous les visiteurs


Recommended Posts

Bonjour,

 

Je cherche comment voir sur le Back Office toutes les adresse IP des visiteurs d'un jour.

 

Actuellement, on peut voir les IP des visiteurs en ligne dans le module stats mais il arrive que j'ai un pic de visite important (genre 50 visites en 2 minutes) sans savoir d'où viennent toutes ces connexions.

La question que je me pose est : sont-ce des visiteurs différents ou un robot qui envoie des paquets de requêtes ?

 

Merci pour votre aide,

Thierry

 

PS: je suis sous PS 1.5.1

Edited by Thierry78125 (see edit history)
Link to comment
Share on other sites

Bonsoir,

 

Ayant désactiver toutes les stats sur ma boutique (j'utilise Google Analytics) sauf celle des visiteurs en ligne.

 

Cependant j'ai apporté quelques modifications pour avoir un historique des visites directement depuis le BO.

 

stats.png

 

Voici le fichier statslive.php modifié (je suis en 1.5.0.17):

 

<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2012 PrestaShop SA
*  @version  Release: $Revision: 7307 $
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_'))
exit;
class StatsLive extends Module
{
private $html = '';
public function __construct()
{
 $this->name = 'statslive';
 $this->tab = 'analytics_stats';
 $this->version = 1.0;
 $this->author = 'PrestaShop';
 $this->need_instance = 0;
 parent::__construct();
 $this->displayName = $this->l('Visitors online');
 $this->description = $this->l('Display the list of customers and visitors currently online.');
}
public function install()
{
 return parent::install() && $this->registerHook('AdminStatsModules');
}
/**
 * Get the number of online customers
 *
 * @return array(array, int) array of online customers entries, number of online customers
 */
private function getCustomersOnline()
{
 $sql = 'SELECT u.id_customer, u.firstname, u.lastname, pt.name as page
   FROM `'._DB_PREFIX_.'connections` c
   LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
   LEFT JOIN `'._DB_PREFIX_.'page` p ON p.id_page = cp.id_page
   LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON p.id_page_type = pt.id_page_type
   INNER JOIN `'._DB_PREFIX_.'guest` g ON c.id_guest = g.id_guest
   INNER JOIN `'._DB_PREFIX_.'customer` u ON u.id_customer = g.id_customer
   WHERE cp.`time_end` IS NULL
 '.Shop::addSqlRestriction(false, 'c').'
 AND TIME_TO_SEC(TIMEDIFF(NOW(), cp.`time_start`)) < 900
   GROUP BY c.id_connections
   ORDER BY u.firstname, u.lastname';
 $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
 return array($results, Db::getInstance()->NumRows());
}
/**
 * Get the number of online visitors
 *
 * @return array(array, int) array of online visitors entries, number of online visitors
 */
private function getVisitorsOnline()
{
 if (Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS'))
 {
  $sql = 'SELECT c.id_guest, c.ip_address, c.date_add, c.http_referer, pt.name as page
 FROM `'._DB_PREFIX_.'connections` c
 LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
 LEFT JOIN `'._DB_PREFIX_.'page` p ON p.id_page = cp.id_page
 LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON p.id_page_type = pt.id_page_type
 INNER JOIN `'._DB_PREFIX_.'guest` g ON c.id_guest = g.id_guest
 WHERE (g.id_customer IS NULL OR g.id_customer = 0)
  '.Shop::addSqlRestriction(false, 'c').'
  AND cp.`time_end` IS NULL
  AND TIME_TO_SEC(TIMEDIFF(NOW(), cp.`time_start`)) < 900
 GROUP BY c.id_connections
 ORDER BY c.date_add DESC';
 }
 else
 {
  $sql = 'SELECT c.id_guest, c.ip_address, c.date_add, c.http_referer
 FROM `'._DB_PREFIX_.'connections` c
 INNER JOIN `'._DB_PREFIX_.'guest` g ON c.id_guest = g.id_guest
 WHERE (g.id_customer IS NULL OR g.id_customer = 0)
  '.Shop::addSqlRestriction(false, 'c').'
  AND TIME_TO_SEC(TIMEDIFF(NOW(), c.`date_add`)) < 900
 ORDER BY c.date_add DESC';
 }
 $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
 return array($results, Db::getInstance()->NumRows());
}
private function getVisitors()
{
 if (Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS'))
 {
  $sql = 'SELECT c.id_guest, c.ip_address, c.date_add, c.http_referer, pt.name as page
 FROM `'._DB_PREFIX_.'connections` c
 LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
 LEFT JOIN `'._DB_PREFIX_.'page` p ON p.id_page = cp.id_page
 LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON p.id_page_type = pt.id_page_type
 INNER JOIN `'._DB_PREFIX_.'guest` g ON c.id_guest = g.id_guest
 WHERE (g.id_customer IS NULL OR g.id_customer = 0)
  '.Shop::addSqlRestriction(false, 'c').'
 GROUP BY c.id_connections
 ORDER BY c.date_add DESC';
 }
 else
 {
  $sql = 'SELECT c.id_guest, c.ip_address, c.date_add, c.http_referer
 FROM `'._DB_PREFIX_.'connections` c
 INNER JOIN `'._DB_PREFIX_.'guest` g ON c.id_guest = g.id_guest
 WHERE (g.id_customer IS NULL OR g.id_customer = 0)
  '.Shop::addSqlRestriction(false, 'c').'
 ORDER BY c.date_add DESC';
 }
 $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
 return array($results, Db::getInstance()->NumRows());
}
public function hookAdminStatsModules($params)
{
 list($customers, $totalCustomers) = $this->getCustomersOnline();
 list($visitors, $totalVisitors) = $this->getVisitorsOnline();
 list($visitors2, $totalVisitors2) = $this->getVisitors();
 $irow = 0;
 $this->html .= '<script type="text/javascript" language="javascript">
  $("#calendar").remove();
 </script>';
 if (!Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS'))
  $this->html .= '<div class="warn">'.
   $this->l('You must activate the option "pages views for each customer" in the "Stats datamining" module in order to see the pages currently viewed by your customers.').'
  </div>';
 $this->html .= '
 <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->l('Customers online').'</legend>';
 if ($totalCustomers)
 {
  $this->html .= $this->l('Total:').' '.(int)$totalCustomers.'
  <table cellpadding="0" cellspacing="0" class="table space">
   <tr><th>'.$this->l('ID').'</th><th>'.$this->l('Name').'</th><th>'.$this->l('Current Page').'</th><th>'.$this->l('View').'</th></tr>';
  foreach ($customers as $customer)
   $this->html .= '
   <tr'.($irow++ % 2 ? ' class="alt_row"' : '').'>
 <td>'.$customer['id_customer'].'</td>
 <td style="width: 200px;">'.$customer['firstname'].' '.$customer['lastname'].'</td>
 <td style="width: 200px;">'.$customer['page'].'</td>
 <td style="text-align: right; width: 25px;">
  <a href="index.php?tab=AdminCustomers&id_customer='.$customer['id_customer'].'&viewcustomer&token='.Tools::getAdminToken('AdminCustomers'.(int)Tab::getIdFromClassName('AdminCustomers').(int)$this->context->employee->id).'"
   target="_blank">
   <img src="../modules/'.$this->name.'/logo.gif" />
  </a>
 </td>
   </tr>';
  $this->html .= '</table>';
 }
 else
  $this->html .= $this->l('There are no customers online.');
 $this->html .= '</fieldset>
 <br />
 <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->l('Visitors online').'</legend>';
 if ($totalVisitors)
 {
  $this->html .= $this->l('Total:').' '.(int)($totalVisitors).'
  <div style="overflow-y: scroll; height: 200px;">
  <table cellpadding="0" cellspacing="0" class="table space">
   <tr><th>'.$this->l('Guest').'</th><th>'.$this->l('IP').'</th><th>'.$this->l('Since').'</th><th>'.$this->l('Current page').'</th><th>'.$this->l('Referrer').'</th></tr>';
  foreach ($visitors as $visitor)
   $this->html .= '<tr'.($irow++ % 2 ? ' class="alt_row"' : '').'>
 <td>'.$visitor['id_guest'].'</td>
 <td style="width: 80px;">'.long2ip($visitor['ip_address']).'</td>
 <td style="width: 100px;">'.substr($visitor['date_add'], 11).'</td>
 <td style="width: 200px;">'.(isset($visitor['page']) ? $visitor['page'] : $this->l('Undefined')).'</td>
 <td style="width: 200px;">'.(empty($visitor['http_referer']) ? $this->l('none') : parse_url($visitor['http_referer'], PHP_URL_HOST)).'</td>
   </tr>';
  $this->html .= '</table></div>';
 }
 else
  $this->html .= $this->l('There are no visitors online.');
 $this->html .= '</fieldset>
 <br />
 <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->l('Historique visiteurs').'</legend>';
 if ($totalVisitors2)
 {
  $this->html .= $this->l('Total:').' '.(int)($totalVisitors2).'
  <div style="overflow-y: scroll; height: 600px;">
  <table cellpadding="0" cellspacing="0" class="table space">
   <tr><th>'.$this->l('Guest').'</th><th>'.$this->l('IP').'</th><th>'.$this->l('Date de connexion').'</th><th>Infos IP</th><th>'.$this->l('Referrer').'</th>';
  foreach ($visitors2 as $visitor2)
   $this->html .= '<tr'.($irow++ % 2 ? ' class="alt_row"' : '').'>
 <td>'.$visitor2['id_guest'].'</td>
 <td style="width: 80px;">'.long2ip($visitor2['ip_address']).'</td>
 <td style="width: 120px;">'.strftime("%d/%m/%y à %T",strtotime($visitor2['date_add'])).'</td>
 <td><a href="http://www.ipgetinfo.com/?mode=ip&lang=fr&ip='.long2ip($visitor2['ip_address']).'" target="blank"><img src="../modules/'.$this->name.'/lien_ip.png"></a></td>
 <td style="width: 200px;">'.(empty($visitor2['http_referer']) ? $this->l('none') : parse_url($visitor2['http_referer'], PHP_URL_HOST)).'</td>
   </tr>';
  $this->html .= '</table></div>';
 }
 else
  $this->html .= $this->l('There are no visitors.');
 $this->html .= '</fieldset>';
 return $this->html;
}
}

 

Bonne soirée

  • Like 1
Link to comment
Share on other sites

Merci infiniment Superbegood !

Exactement ce que je recherchais. Testé et approuvé avec mon PS 1.5.1.

 

Je suis persuadé que cette modif devrait être intégré d'office dans PS.

 

Petite question technique de débutant avec PS : je ne vois pas la table PS_STATSDATA avec PhpMyAdmin, elle est cachée ?

Link to comment
Share on other sites

J'ai repris la modif proposée par Superbegood et ai apporté quelques changements :

  • Le tableau de l'historique est affiché dans la section "Tableau de bord statistiques" plutôt que "Visiteurs en ligne"
  • Le lien vers le whois a été changé pour infosniper.com qui me semble plus précis et mis en hyperlien sur l'adresse IP
  • La liste n'affiche que les connexions dans le segment de date défini

 

Fichier statsforecast ci-attaché.

Testé avec PS 1.5.1

statsforecast.php

Link to comment
Share on other sites

  • 6 months later...

Bonsoir,

 

Cet historique semble très utile.

 

Serait-il possible d'apporter des modifications afin qu'il soit compatible pour Prestashop 1.4.9 ?

Malheureusement je ne développe pas.

 

Merci ;-)

Link to comment
Share on other sites

Bonjour

 

Switchboard est le fichier complet statslive.php ou une partie du fichier ? j'ai mis en place mais je vois pas de modification entre l'original et celui-ci.

 

idem pour Thierry78125 le fichier statsforecast.php rien dans l'administration

 

Pourriez vous faire un pas à pas complet pour placer et activer ces statistiques pour les plus novices que moi :) Merci

Link to comment
Share on other sites

Il s'agit du fichier complet. Mais je ne sais pas si cela fonctionne sur une version différente de PS 1.5.0.17

 

Après ceci

return array($results, Db::getInstance()->NumRows());

Coller ceci

private function getVisitors()
{
 if (Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS'))
 {
  $sql = 'SELECT c.id_guest, c.ip_address, c.date_add, c.http_referer, pt.name as page
 FROM `'._DB_PREFIX_.'connections` c
 LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
 LEFT JOIN `'._DB_PREFIX_.'page` p ON p.id_page = cp.id_page
 LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON p.id_page_type = pt.id_page_type
 INNER JOIN `'._DB_PREFIX_.'guest` g ON c.id_guest = g.id_guest
 WHERE (g.id_customer IS NULL OR g.id_customer = 0)
  '.Shop::addSqlRestriction(false, 'c').'
 GROUP BY c.id_connections
 ORDER BY c.date_add DESC';
 }
 else
 {
  $sql = 'SELECT c.id_guest, c.ip_address, c.date_add, c.http_referer
 FROM `'._DB_PREFIX_.'connections` c
 INNER JOIN `'._DB_PREFIX_.'guest` g ON c.id_guest = g.id_guest
 WHERE (g.id_customer IS NULL OR g.id_customer = 0)
  '.Shop::addSqlRestriction(false, 'c').'
 ORDER BY c.date_add DESC';
 }
 $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
 return array($results, Db::getInstance()->NumRows());
}

Après ceci

list($visitors, $totalVisitors) = $this->getVisitorsOnline();

Coller ceci

list($visitors2, $totalVisitors2) = $this->getVisitors();

On rétrécit la hauteur de la vue visiteur en ligne

Remplacer

<div style="overflow-y: scroll; height: 600px;">

Par

<div style="overflow-y: scroll; height: 200px;">

Affichage en BO

Après

$this->html .= $this->l('There are no visitors online.');

Ajouter ceci

 $this->html .= '</fieldset>
 <br />
 <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->l('Historique visiteurs').'</legend>';
 if ($totalVisitors2)
 {
  $this->html .= $this->l('Total:').' '.(int)($totalVisitors2).'
  <div style="overflow-y: scroll; height: 600px;">
  <table cellpadding="0" cellspacing="0" class="table space">
<tr><th>'.$this->l('Guest').'</th><th>'.$this->l('IP').'</th><th>'.$this->l('Date de connexion').'</th><th>Infos IP</th><th>Whois</th><th>'.$this->l('Referrer').'</th>';
  foreach ($visitors2 as $visitor2)
$this->html .= '<tr'.($irow++ % 2 ? ' class="alt_row"' : '').'>
 <td>'.$visitor2['id_guest'].'</td>
 <td style="width: 80px;">'.long2ip($visitor2['ip_address']).'</td>
 <td style="width: 120px;">'.strftime("%d/%m/%y à %T",strtotime($visitor2['date_add'])).'</td>
 <td><a href="http://www.infosniper.net/index.php?ip_address='.long2ip($visitor2['ip_address']).'" target="blank"><img src="../modules/'.$this->name.'/lien_ip.png"></a></td>
 <td><a href="http://whois.domaintools.com/'.long2ip($visitor2['ip_address']).'" target="blank"><img src="../modules/'.$this->name.'/whois.png"></a></td>
 <td style="width: 200px;">'.(empty($visitor2['http_referer']) ? $this->l('none') : parse_url($visitor2['http_referer'], PHP_URL_HOST)).'</td>
</tr>';
  $this->html .= '</table></div>';
 }
 else
  $this->html .= $this->l('There are no visitors.');

Link to comment
Share on other sites

Bonjour,

 

Au fait, désolé d'avoir déterré ce topic. Mais il en vaut la peine !

 

Par copier/coller du code complet cela donne un message d'erreur en bas de page :

 

Fatal error: Call to undefined method Shop::addSqlRestriction()
in /var/www/vhosts/DOMAINE/modules/statslive/statslive.php on line 62

 

C'est-à-dire cette ligne :

'.Shop::addSqlRestriction(false, 'c').'

 

et à priori à chaque fois que cette ligne est appelée.

 

Merci.

Edited by sajou (see edit history)
Link to comment
Share on other sites

Je n'avais pas vu votre version (1.4.9) plus haut...

 

Essayez cette fonction à la place

   private function getVisitors()
   {
       if (Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS'))
       {
           $query = 'SELECT c.id_guest, c.ip_address, c.date_add, c.http_referer, pt.name as page
           FROM `'._DB_PREFIX_.'connections` c
           LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
           LEFT JOIN `'._DB_PREFIX_.'page` p ON p.id_page = cp.id_page
           LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON p.id_page_type = pt.id_page_type
           INNER JOIN `'._DB_PREFIX_.'guest` g ON c.id_guest = g.id_guest
           WHERE cp.`time_end` IS NULL
           AND (g.id_customer IS NULL OR g.id_customer = 0)
           GROUP BY c.id_connections
           ORDER BY c.date_add DESC';
       }
       else
       {
           $query = 'SELECT c.id_guest, c.ip_address, c.date_add, c.http_referer
           FROM `'._DB_PREFIX_.'connections` c
           INNER JOIN `'._DB_PREFIX_.'guest` g ON c.id_guest = g.id_guest
           WHERE (g.id_customer IS NULL OR g.id_customer = 0)
           ORDER BY c.date_add DESC';
       }

       $result =  Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($query);
       return array($result, Db::getInstance()->NumRows());
   }

Edited by SWITCHBOARD (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

Bonjour,

 

En vérité je trouverais interressant d'identifier uniquement les ip des visiteurs réalisant un panier ou une commande car faire une liste de toutes les ip des visiteurs n'a pas de sens...si vous avez un grand nombre de visiteurs par mois cela deviendrais complexe à gérer dans ce cas il serait mieux d'utiliser google analytics

Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...
  • 1 year later...
  • 1 year later...
  • 1 month later...

Bonjour,

 

Je serais aussi intéressée pour savoir si cette manipulation fonctionne sous Prestashop 1.6, étant donné que ma boutique a des visites d'IPs identiques à quelques secondes d'écart assez régulièrement, quand je suis présente pour l'observer, ça serait très utile de pouvoir utiliser ceci !

 

D'avance merci ! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...