Jump to content

Recommended Posts

Hello,

 

I'm using a direct feature on my site, and on redirect I want to record unique hits, Ip Address, and referrer, so far, the code below records unique hits, and ip address, but i want it to record referrar aswell (it records data to data.txt):

 

<?php
$filename = "hits.txt";

$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;

$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename));
fclose($fd);
$fd = fopen ($filename , "w");
$fcounted = $fstring."n".getenv("REMOTE_ADDR");
$fout= fwrite ($fd , $fcounted );
fclose($fd);
?>

 

I have this on redirect page

 

<?php
include ('counter.php');
?>

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/211634-record-referrer-aswell/
Share on other sites

Well, it does work because i tried the refer, and it gave a link, but i couldn't get all 3 to work, i used:

 

<?php
$filename = "hits.txt";

$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;
echo "$refer"; 
$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename));
fclose($fd);
$fd = fopen ($filename , "w");
$fcounted = $fstring."n".getenv("REMOTE_ADDR");
$refer = $_SERVER["HTTP_REFERER"];
$fout= fwrite ($fd , $fcounted );
fclose($fd);
?>

 

And, clicked my link from youtube twice, this is the outcome on the txt doc:

 

n78.148.52.111n78.148.52.111

You didn't write the referrer to the file, you only stored it in a variable.

<?php
$filename = "hits.txt";

$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;
echo "$refer"; 
$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename));
fclose($fd);
$fd = fopen ($filename , "w");
$fcounted = $fstring."n IP ".getenv("REMOTE_ADDR");
$refer = ' Referrer ' . $_SERVER["HTTP_REFERER"] . "\n";
$fout= fwrite ($fd , $fcounted . $refer);
fclose($fd);
?>

You didn't write the referrer to the file, you only stored it in a variable.

<?php
$filename = "hits.txt";

$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;
echo "$refer"; 
$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename));
fclose($fd);
$fd = fopen ($filename , "w");
$fcounted = $fstring."n IP ".getenv("REMOTE_ADDR");
$refer = ' Referrer ' . $_SERVER["HTTP_REFERER"] . "\n";
$fout= fwrite ($fd , $fcounted . $refer);
fclose($fd);
?>

 

thanks it's working better now, however i went on it twice from youtube from two different vids, this is how the whole .txt came out:

n IP 78.148.52.111 Referrer http://www.youtube.com/watch?v=3dPZ23KVoPQ
n IP 78.148.52.111 Referrer http://www.youtube.com/watch?v=I8nM7XrjjkA

 

It doesn't seem to be showing the unique hit counter number which would of obviously said "1" thanks for your help.

I currently have it like this:

 

<?php
$filename = "hits.txt";

$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;
echo "$refer"; 
$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename));
fclose($fd);
$fd = fopen ($filename , "w");
$fcounted = $fstring."IP: ".getenv("REMOTE_ADDR");
$refer = ' Referrer: ' . $_SERVER["HTTP_REFERER"] . "\n";
$fout= fwrite ($fd , $fcounted . $refer);
fclose($fd);
?>

 

When i go on it twice from my pc it does:

IP: 78.148.52.111 Referrer: youtube.com etc whereever user clicked. 
IP: 78.148.52.111 Referrer: youtube.com etc whereever user clicked.

 

I basicly want it to do this:

 

Unique hits: 43
IP: 78.148.52.111 Referrer: youtube.com etc whereever user clicked. 
IP: 78.148.52.111 Referrer: youtube.com etc whereever user clicked.

 

Etc, thanks.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.