Advertisement:

Author Topic: [Tip and Trick] Finding out referrer of the users coming to your site  (Read 47673 times)

Offline SwapsRulez

  • Jr. Member
  • **
  • Posts: 208
  • Gender: Male
  • Its better to burn out than to fade away...!!!
    • Project-BB
Hello guys, I've written a simple code which can check the referrer of the users coming to your site. It will find out the referrers of the users. But I have made it so that the file won't be huge and it will still track perfect referrers. For that I've done following things.

1. Removed bots, slurp, crawlers, spiders from the referrer's list.
2. Removed the referrers which are coming from your own site
3. Removed the users who don't have referrers (They know your site  :P)

And The referrer file will display the following information,

Referrer : http://search.live.com/results.aspx?q=project-bb.org&sourceid=Mozilla-search&form=CHROME
User Agent : mozilla/5.0 (windows; u; windows nt 6.1; en-us; rv:1.9.0.5) gecko/2008120122 firefox/3.0.5
IP Address : http://whois.domaintools.com/127.0.0.1
Date and Time : Sunday 01st February 2009 04:59:45 AM

So you have to follow the just simple steps. If you have installed custom actions mod, it can be improvised. But for the time being, I'm giving instructions for normal users.

Steps :

1. In the first step, you have to find out the index.template.php file. This file is in the \Themes\Default folder. If you are using custom theme other than default, then go browse to \Themes\ThemeName and then edit the index.template.php file.

Make sure to make backup of file first.

2. You have to put the following code anywhere in the body tag. I've written it inside function template_body_above().
Just search for template_main_above() and inside that put the following code.

Code: [Select]
/* Getting the referrer information and saving it to text file */
$referrer=strtolower(getenv('HTTP_REFERER'));
$agent=strtolower($_SERVER['HTTP_USER_AGENT']);
if (empty($referrer) || ereg("slurp", $agent) || ereg("bot", $agent) || ereg("spider", $agent) || ereg("crawler", $agent) || ereg("http://www.project-bb.org/", $referrer)) {
}
else{
$message = "\n\nReferrer : " . getenv('HTTP_REFERER') . "\nUser Agent : ". strtolower($_SERVER['HTTP_USER_AGENT']) . "\nIP Address : http://whois.domaintools.com/" . getenv('REMOTE_ADDR') . "\nDate and Time : " . date("l dS F Y h:i:s A"). "\n";
$fp=fopen("referrer.txt", 'a' );
fwrite($fp, $message);
fclose($fp);
}
/* End of referrer information retrieval code */

3. You need to edit the code to match the information of your site. Replace http://www.project-bb.org/ with your site name and also replace referrer.txt with the filename you want to save the referrer information.

4. Now save the file and check if site works. If the site works, then everything is working fine and function is writing the file. If not the check for the syntax errors or file permissions.

5. Now the basic functionality is achieved. The log will be saved in the file referrer.txt or the filename you've specified. Just browse that file from the browser to see the referrer information.

go to this URL : http://www.yoursitename.com/referrer.txt  or http://www.yoursitename.com/referrerfilename.txt

If there is no referrer information found in the file. Let's make a new entry in it. Just open google and put your site name. open the result of your site from the google. You'll get entry added to that file.

6. That's the end of it.  :D

If you have custom actions mod installed, you can create custom action to check the referrer file instead of typing URL each time.

Just go to the custom action, create new action with type php.
Set proper permissions.

And paste the following code in the Template Code box:

To check the referrer file

Code: [Select]
echo '<a href="URL OF THE ACTION TO CLEAR THE REFERRER FILE"><b>Delete Administrative Referrer File</b></a>';

$fp = fopen ('referrer.txt', 'r');
$contents = fread ($fp, filesize ('referrer.txt'));
fclose ($fp);
$contents = str_replace ("\n", "<br />", $contents);
echo $contents;

To clear the referrer file

Code: [Select]
unlink('referrer.txt');
echo '<a href="URL OF THE CHECK REFERRER FILE CUSTOM ACTION"><b>Go Back to Administrative Referrer File</b></a>';
echo '<br /><a href="URL OF THE SITE"><b>Go Back to Project-BB.org</b></a>';

Also remember to replace the name of your site, custom referrer file name and URL's of the custom action accordingly.

I recommend to give something other name for privacy reasons.  ;D

Replies, comments are welcome.

Thanks to Tanchannel, Erry, Triston and Eddie in writing this code. :)

SMF has given me a lot for free, its just a simple try to give something in return. Hope you understand.  :)

PS: I will be happy if this moved to Tips and Tricks section.
« Last Edit: February 28, 2009, 11:53:22 AM by SwapsRulez »
Project-BB.org : Educational Forum For Engineering, Diploma & Technical Students

The Engineering, Diploma & All technical students lounge for Free Projects, Seminars, Syllabus, Question Papers, College Assignments, Placement Papers, E-Books, Company Information & other technical stuffs.

Offline HR

  • Jr. Member
  • **
  • Posts: 321
  • Gender: Male
  • There is only ONE 'Reality!
    • http://only-harshreality.com/forums/
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #1 on: February 01, 2009, 11:04:52 AM »
NOw.. if you had this packaged as a mod with a quick delete option and what not Id be delighted.
I can explain this as simply as possible.. If I do it & implement I guarantee it.
 If I do it and you implement it its a crap shoot.

Offline SwapsRulez

  • Jr. Member
  • **
  • Posts: 208
  • Gender: Male
  • Its better to burn out than to fade away...!!!
    • Project-BB
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #2 on: February 01, 2009, 12:11:21 PM »
I don't know much about creating mods. Also If someone wants to make a mod of this code. They are more than welcome. :)
Project-BB.org : Educational Forum For Engineering, Diploma & Technical Students

The Engineering, Diploma & All technical students lounge for Free Projects, Seminars, Syllabus, Question Papers, College Assignments, Placement Papers, E-Books, Company Information & other technical stuffs.

Offline weisus

  • Semi-Newbie
  • *
  • Posts: 58
    • Citrus County Information Zone
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #3 on: February 10, 2009, 12:29:50 PM »
Thanks for the code! This should help out a great deal with my advertising efforts, thank you for sharing it.

Offline SwapsRulez

  • Jr. Member
  • **
  • Posts: 208
  • Gender: Male
  • Its better to burn out than to fade away...!!!
    • Project-BB
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #4 on: February 10, 2009, 01:04:28 PM »
Thanks for the code! This should help out a great deal with my advertising efforts, thank you for sharing it.

Atleast someone is there, who is getting help from my code. :)
You're welcome bud. :D
Project-BB.org : Educational Forum For Engineering, Diploma & Technical Students

The Engineering, Diploma & All technical students lounge for Free Projects, Seminars, Syllabus, Question Papers, College Assignments, Placement Papers, E-Books, Company Information & other technical stuffs.

Offline NDFF

  • Semi-Newbie
  • *
  • Posts: 36
    • Dansk Fjerkræ Forum
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #5 on: February 22, 2009, 06:33:30 AM »
Works great, allthough you should change the explanation. There is no template_body_above(), it's called template_main_above()

Offline SwapsRulez

  • Jr. Member
  • **
  • Posts: 208
  • Gender: Male
  • Its better to burn out than to fade away...!!!
    • Project-BB
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #6 on: February 23, 2009, 11:47:30 AM »
Works great, allthough you should change the explanation. There is no template_body_above(), it's called template_main_above()

Ohh sorry then. Because I'm using custom theme that's why. :P
Project-BB.org : Educational Forum For Engineering, Diploma & Technical Students

The Engineering, Diploma & All technical students lounge for Free Projects, Seminars, Syllabus, Question Papers, College Assignments, Placement Papers, E-Books, Company Information & other technical stuffs.

Offline 1000bech

  • Semi-Newbie
  • *
  • Posts: 18
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #7 on: March 03, 2009, 02:33:29 PM »
thanks, works great!
;)

Offline HR

  • Jr. Member
  • **
  • Posts: 321
  • Gender: Male
  • There is only ONE 'Reality!
    • http://only-harshreality.com/forums/
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #8 on: March 04, 2009, 10:30:28 AM »
Tweaking... 2.0b4

./Themes/default/languages/Modifications.english.php
Find:
Code: [Select]
?>
Add Before that:
Code: [Select]
// Additional Logging
$txt['enableLogReferral'] = 'Enable referrals logging?';
$txt['enableLogReferralDesc'] = 'Additional logging to see where users are coming from';
$txt['LogReferralPath'] = 'Path to store referral logs:<br><a href="' . $modSettings['LogReferralPath'] . '">°Download</a>';
$txt['LogReferralPathDesc'] = 'Using forum root as point of reference <i>ex. Logs/filename</i>';

./Sources/ManageSettings.php
Find:
Code: [Select]
            array('check', 'enableErrorLogging'),
            array('check', 'enableErrorQueryLogging'),
            array('check', 'securityDisable'),
        '',
Add After that:
Code: [Select]
            array('check', 'enableLogReferral', 'subtext' => $txt['enableLogReferralDesc']),
            array('text', 'LogReferralPath', 'subtext' => $txt['LogReferralPathDesc']),
        '',

This gives us a checkbox to enable/disable and a link to download in Security & Moderation.
the mod additions to index.template can then use
Code: [Select]
if (!empty($modSettings['enableLogReferral']) && !empty($modSettings['LogReferralPath']))
So it can be turned on/off, of course for it to work it will require a path as well as activation.. the above template addition will need altered to use $modSettings['LogReferralPath'] rather than a filename..

But Im just talking off the top of my head.
I can explain this as simply as possible.. If I do it & implement I guarantee it.
 If I do it and you implement it its a crap shoot.

Online Dzonny

  • Lead Localizer
  • SMF Super Hero
  • *
  • Posts: 11,610
  • Gender: Male
  • No sleep...
    • dzontra.nikola on Facebook
    • Dzonny on GitHub
    • dzontranikola on LinkedIn
    • @opusteniforum on Twitter
    • Samo opusteno
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #9 on: March 05, 2009, 09:01:20 AM »
great thing, work excelent... :)

Offline John Sivags

  • Semi-Newbie
  • *
  • Posts: 26
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #10 on: March 06, 2009, 04:03:13 PM »
May i have a chance to disturb you guys please ? lol

I am sorry for my ignorance. I am new for SMF. So, still i don't know about HTML page in ACP. Where i have to go to look on it, and set codes ?

And this post is great at me. I want it. But, don't know where (in ACP) to put them lol

Please, if you guys don't mind, can you tell me, where to go and put codes ?

Oh, and my forum's present version is 1.1.7 :(

Trying to upgrade it too.

Online Dzonny

  • Lead Localizer
  • SMF Super Hero
  • *
  • Posts: 11,610
  • Gender: Male
  • No sleep...
    • dzontra.nikola on Facebook
    • Dzonny on GitHub
    • dzontranikola on LinkedIn
    • @opusteniforum on Twitter
    • Samo opusteno
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #11 on: March 06, 2009, 04:29:58 PM »
John, you have to add this code to index.tempalte.php of theme that u're using, somewhere before or after template_main_above().
Code: [Select]
/* Getting the referrer information and saving it to text file */
$referrer=strtolower(getenv('HTTP_REFERER'));
$agent=strtolower($_SERVER['HTTP_USER_AGENT']);
if (empty($referrer) || ereg("slurp", $agent) || ereg("bot", $agent) || ereg("spider", $agent) || ereg("crawler", $agent) || ereg("http://www.project-bb.org/", $referrer)) {
}
else{
$message = "\n\nReferrer : " . getenv('HTTP_REFERER') . "\nUser Agent : ". strtolower($_SERVER['HTTP_USER_AGENT']) . "\nIP Address : http://whois.domaintools.com/" . getenv('REMOTE_ADDR') . "\nDate and Time : " . date("l dS F Y h:i:s A"). "\n";
$fp=fopen("referrer.txt", 'a' );
fwrite($fp, $message);
fclose($fp);
}
/* End of referrer information retrieval code */

Just rename project bb with adress of your forum.
And then browse www.blah.com/forumdir/referrer.txt

Offline SwapsRulez

  • Jr. Member
  • **
  • Posts: 208
  • Gender: Male
  • Its better to burn out than to fade away...!!!
    • Project-BB
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #12 on: March 19, 2009, 12:20:51 PM »
HR, any chance of making one more setting to read the file from admin panel itself. I mean there will be a tab in modification section where you'll have a setting to turn it on or off. Also you can set 2 values. First one which you want to exclude from referrer and second one you want to exclude from agent. And those values will be set in comma seperated form. And then there will be a link to check the file. :)

Just a though, I know you know a lot in SMF. I just looked at your coding, you rock buddy. thanks. :)
Project-BB.org : Educational Forum For Engineering, Diploma & Technical Students

The Engineering, Diploma & All technical students lounge for Free Projects, Seminars, Syllabus, Question Papers, College Assignments, Placement Papers, E-Books, Company Information & other technical stuffs.

Offline Joey Smith™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,356
  • Gender: Male
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #13 on: April 25, 2009, 03:10:10 AM »
@HR

You going to package this up?

Offline Tiribulus

  • Sophist Member
  • *****
  • Posts: 1,014
  • Gender: Male
    • Tiribulus on Facebook
    • No Other God
Dude, this is like unspeakably kick@$$. Works like a charm and took 2 minutes to set up. For some reason adding the code after template_main_above() broke my site in a hideous way, but adding it before works jist peachy.

Offline HR

  • Jr. Member
  • **
  • Posts: 321
  • Gender: Male
  • There is only ONE 'Reality!
    • http://only-harshreality.com/forums/
@HR

You going to package this up?

I dot actually do packages however I might be able to follow the suggestion above so that it could be accessed from the admin area.. ATM IM still using Beta 4 so let me get up to RC1 and see what I can do with it.. might be able to go so far as to expand the internal logging features to include the reffed. Been awhile sine I had this one in my head so I need to freshen up.
I can explain this as simply as possible.. If I do it & implement I guarantee it.
 If I do it and you implement it its a crap shoot.

Offline MikeJones

  • Newbie
  • *
  • Posts: 1
Sweet!!!!!!!!!! cant wait to implement this

Offline skydiamond

  • Semi-Newbie
  • *
  • Posts: 19
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #17 on: September 02, 2009, 09:07:22 AM »
I want to add these informations in this mod for each user.

Offline - danny

  • Jr. Member
  • **
  • Posts: 287
  • Gender: Male
    • The ThirdEye Concept
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #18 on: September 05, 2009, 05:47:28 PM »
can this be modified and placed in a block, visible to all users?

Offline - danny

  • Jr. Member
  • **
  • Posts: 287
  • Gender: Male
    • The ThirdEye Concept
Re: [Tip and Trick] Finding out referrer of the users coming to your site
« Reply #19 on: September 12, 2009, 04:10:37 PM »
anyone? :|