Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getRealIP() {
- if (!empty($_SERVER['HTTP_CLIENT_IP']))
- return $_SERVER['HTTP_CLIENT_IP'];
- if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
- return $_SERVER['HTTP_X_FORWARDED_FOR'];
- return $_SERVER['REMOTE_ADDR'];
- }
- // Si se necesita guardar las IP en un archivo aparte
- define("USE_DETAIL", FALSE);
- define("FOLDER", "counterdata");
- $id = $_GET['id'];
- $url = $_GET['url'];
- if($id) {
- $updateFile = FOLDER."/clicks_banner_" . $id . ".txt";
- if(isset($_GET['debug']))
- echo $updateFile.'<br>';
- // Ver si existe el archivo, si existe se lee el contenido, se le
- // suma 1 y se reescribe con el nuevo valor
- if(file_exists($updateFile)) {
- $fileContents = file_get_contents($updateFile);
- $fileContents = $fileContents + 1;
- $fp = fopen($updateFile, "w");
- fwrite($fp, $fileContents);
- fclose($fp);
- if(isset($_GET['debug']))
- echo $fileContents;
- if(USE_DETAIL) {
- $updateFile = "clicks_banner_" . $id . "_detalle.txt";
- $fileContents = getRealIP();
- $fp = fopen($updateFile, "w");
- fwrite($fp, $fileContents);
- fclose($fp);
- }
- } else {
- // Si no existe el archivo se crea uno nuevo con un 1 para
- // mantener la estadística
- $fp = fopen($updateFile, "w");
- fwrite($fp, "1");
- fclose($fp);
- if(isset($_GET['debug']))
- echo "1";
- if(USE_DETAIL) {
- $updateFile = "clicks_banner_" . $id . "_detalle.txt";
- $fileContents = getRealIP(). " redireccionado a: " . $url;
- $fp = fopen($updateFile, "w");
- fwrite($fp, $fileContents);
- fclose($fp);
- }
- }
- }
- if($url) {
- if(!isset($_GET['debug']))
- header("Location: " . $url);
- }
- ?>
Add Comment
Please, Sign In to add comment