Guest User

Untitled

a guest
May 20th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. <?php
  2. function getRealIP() {
  3.     if (!empty($_SERVER['HTTP_CLIENT_IP']))
  4.         return $_SERVER['HTTP_CLIENT_IP'];
  5.     if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  6.         return $_SERVER['HTTP_X_FORWARDED_FOR'];
  7.     return $_SERVER['REMOTE_ADDR'];
  8. }
  9. // Si se necesita guardar las IP en un archivo aparte
  10. define("USE_DETAIL", FALSE);
  11. define("FOLDER", "counterdata");
  12. $id = $_GET['id'];
  13. $url = $_GET['url'];
  14.  
  15. if($id) {
  16.     $updateFile = FOLDER."/clicks_banner_" . $id . ".txt";
  17.    
  18.     if(isset($_GET['debug']))
  19.         echo $updateFile.'<br>';
  20.    
  21.     // Ver si existe el archivo, si existe se lee el contenido, se le
  22.     // suma 1 y se reescribe con el nuevo valor
  23.     if(file_exists($updateFile)) {
  24.         $fileContents = file_get_contents($updateFile);
  25.         $fileContents = $fileContents + 1;
  26.         $fp = fopen($updateFile, "w");
  27.         fwrite($fp, $fileContents);
  28.         fclose($fp);
  29.        
  30.         if(isset($_GET['debug']))
  31.             echo $fileContents;
  32.        
  33.         if(USE_DETAIL) {
  34.             $updateFile = "clicks_banner_" . $id . "_detalle.txt";
  35.             $fileContents = getRealIP();
  36.             $fp = fopen($updateFile, "w");
  37.             fwrite($fp, $fileContents);
  38.             fclose($fp);
  39.         }
  40.     } else {
  41.         // Si no existe el archivo se crea uno nuevo con un 1 para
  42.         // mantener la estadística
  43.         $fp = fopen($updateFile, "w");
  44.         fwrite($fp, "1");
  45.         fclose($fp);
  46.        
  47.         if(isset($_GET['debug']))
  48.             echo "1";
  49.        
  50.         if(USE_DETAIL) {
  51.             $updateFile = "clicks_banner_" . $id . "_detalle.txt";
  52.             $fileContents = getRealIP(). " redireccionado a: " . $url;
  53.             $fp = fopen($updateFile, "w");
  54.             fwrite($fp, $fileContents);
  55.             fclose($fp);
  56.         }
  57.     }
  58. }
  59.  
  60. if($url) {
  61.     if(!isset($_GET['debug']))
  62.         header("Location: " . $url);
  63. }
  64. ?>
Add Comment
Please, Sign In to add comment