sphinx Posted August 24, 2010 Share Posted August 24, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/211634-record-referrer-aswell/ Share on other sites More sharing options...
sphinx Posted August 24, 2010 Author Share Posted August 24, 2010 bump Quote Link to comment https://forums.phpfreaks.com/topic/211634-record-referrer-aswell/#findComment-1103270 Share on other sites More sharing options...
sphinx Posted August 24, 2010 Author Share Posted August 24, 2010 bump Quote Link to comment https://forums.phpfreaks.com/topic/211634-record-referrer-aswell/#findComment-1103302 Share on other sites More sharing options...
The Eagle Posted August 24, 2010 Share Posted August 24, 2010 So many bumps... eventually your question will be answered not really a need to bump it constantly. $refer = $_SERVER["HTTP_REFERER"]; echo "$refer"; Why not use that? Quote Link to comment https://forums.phpfreaks.com/topic/211634-record-referrer-aswell/#findComment-1103307 Share on other sites More sharing options...
KevinM1 Posted August 24, 2010 Share Posted August 24, 2010 You're not guaranteed that HTTP_REFERER will work, as not all user agents set it. For more info, see: http://www.php.net/manual/en/reserved.variables.server.php Quote Link to comment https://forums.phpfreaks.com/topic/211634-record-referrer-aswell/#findComment-1103308 Share on other sites More sharing options...
sphinx Posted August 24, 2010 Author Share Posted August 24, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/211634-record-referrer-aswell/#findComment-1103310 Share on other sites More sharing options...
The Eagle Posted August 24, 2010 Share Posted August 24, 2010 What I posted will work, but you cannot trust it always. It can be sometimes forged or not even set at all, they could have opened it up in a new window and the referrer is pretty much garbage then. Quote Link to comment https://forums.phpfreaks.com/topic/211634-record-referrer-aswell/#findComment-1103317 Share on other sites More sharing options...
sphinx Posted August 24, 2010 Author Share Posted August 24, 2010 It's not major, I don't need it for everybody, just a majority so that I can see where they came from. Quote Link to comment https://forums.phpfreaks.com/topic/211634-record-referrer-aswell/#findComment-1103318 Share on other sites More sharing options...
jcbones Posted August 24, 2010 Share Posted August 24, 2010 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/211634-record-referrer-aswell/#findComment-1103350 Share on other sites More sharing options...
sphinx Posted August 24, 2010 Author Share Posted August 24, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/211634-record-referrer-aswell/#findComment-1103360 Share on other sites More sharing options...
sphinx Posted August 25, 2010 Author Share Posted August 25, 2010 bump Quote Link to comment https://forums.phpfreaks.com/topic/211634-record-referrer-aswell/#findComment-1103483 Share on other sites More sharing options...
sphinx Posted August 25, 2010 Author Share Posted August 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/211634-record-referrer-aswell/#findComment-1103501 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.