MyBB Community Forums

Full Version: Referrer Mod
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Ok then...
Open /global.php and go to the bottom of the file (make a backup of this file first)
You should see a line with
//START REFERRER MOD
look near the very bottom and you should see
//END REFERRER MOD
Delete the code between these lines

In the space you just deleted, put this code
//START REFERRER MOD v 1.0.0
if($settings['referrer_on'] == "yes"){
	$referrer = addslashes($_SERVER['HTTP_REFERER']);
	$self = addslashes($_SERVER['PHP_SELF'] . (empty($_SERVER['argv']) ? "" : "?" . implode("&", $_SERVER['argv'])));
	if(empty($referrer))
	{
		if($mybb->user['uid'] == 1)
		{
			echo "Empty referrer<br/>";
		}
	}
	elseif(preg_match("/" . preg_quote($_SERVER['HTTP_HOST'], "/") . "(.*)/", $referrer))
	{
		if($mybb->user['uid'] == 1)
		{
			echo "Referred from own site<br/>";
		}
	}
	else{
		if($mybb->user['uid'] == 1)
		{
			echo "$referrer<br/>";
		}
		//Having to use SELECT because an update will not work/return error
		$sql = "SELECT hits FROM ".TABLE_PREFIX."referrer WHERE from_link = '" . $referrer . "' AND to_link = '" . $self . "'";
		if(($result = $db->query($sql, TRUE))){
			if(!$db->fetch_array($result)){
				$sql = "INSERT INTO ".TABLE_PREFIX."referrer (from_link, to_link, hits, first_date, last_date) VALUES('$referrer', '$self', 1, NOW(), NOW())";
				if(!($result = $db->query($sql, TRUE))){
					if($mybb->user['uid'] == 1)
					{
						echo "Could not insert referrer<br/>";
					}
				}
			}
			else{
				$sql = "UPDATE ".TABLE_PREFIX."referrer SET hits = hits + 1, last_date = NOW() WHERE from_link = '$referrer' AND to_link = '$self'";
				if(!($result = $db->query($sql, TRUE))){
					if($mybb->user['uid'] == 1)
					{
						echo "Could not update referrer<br/>";
					}
				}
			}
		}
	}
}
//END REFERRER MOD v 1.0.0
Upload the changed global.php to your forums

I am assuming you are the admin with a user id of 1. If your id is not 1, you should change the relevant lines (obvious?).
Now when you visit any page on your site, you should see a line of text at the top. Visit a few pages on your site normally. The line at the top should say "Empty referrer" or "Referred from own site". Now try using your signature. See what it says at the top of the screen.
Now when I try to view a thread... I get this error:
Warning: Cannot modify header information - headers already sent by (output started at /usr/local/djcsites/dajoob.com/firefox/global.php:378) in /usr/local/djcsites/dajoob.com/firefox/showthread.php on line 83

And when I go to view a forum, this is at the top of the page:
Warning: Cannot modify header information - headers already sent by (output started at /usr/local/djcsites/dajoob.com/firefox/global.php:378) in /usr/local/djcsites/dajoob.com/firefox/inc/functions.php on line 803

and on some other threads I now get
Warning: Cannot modify header information - headers already sent by (output started at /usr/local/djcsites/dajoob.com/firefox/global.php:378) in /usr/local/djcsites/dajoob.com/firefox/inc/plugins/thx.php on line 90

........
Yes I know that will happen. I just need what it says. It's a temporary problem until the referrer mod is fixed.
Pages: 1 2