Jump to content

Record referrer aswell.


sphinx

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.