Bad Boy Blog, an unofficial Diddy and Bad Boy fan blog

Bookmark and Share

Tracking Visitors Throughout Your PHP Enabled Website

Tracking Visitors Throughout Your PHP Enabled Website

Postby Lee McDermott » February 2nd 2003, 8:31 am

The following tutorial is my first. Please let me know if you like it.

This will briefly teach you how to dynamically track the location of visitors throughout your website.

phpBB features a "Who is Online" feature displayed within the Administration index. What some people don't know is that it's possible to create your own options such as "Viewing site Homepage," etc.

To do this, your site must first initiate the userdata variable throughout every page you wish to track visitors. For this to work, all required phpBB config files need to be included. This can be done by pasting this first piece of code into your page(s):

Code: Select all
<?define('IN_PHPBB', true); 
$site_root_path = './';			// MAY NEED CHANGING
$phpbb_root_path2 = 'forum/';		// MAY NEED CHANGING
$phpbb_root_path = $site_root_path . $phpbb_root_path2; 
include($phpbb_root_path . ''); 
include($phpbb_root_path . 'common.php'); 

// Start session management
$userdata = session_pagestart($user_ip, PAGE_INDEX);
// End session management

Notice the part reading "PAGE_INDEX." This tells the phpBB session management system that you are viewing the Forum Index which is eventually displayed in the Admin CP. What we're gonna do is alter this to display different messages whilst also keeping old ones intact.

Next step: Open language/lang_english/lang_main.php with your favorite .txt editor and find the following line: $lang['Viewing_FAQ'] = 'Viewing FAQ';

Below this line, add a new variable to the array stating your own message. ie: $lang['Viewing_Homepage'] = 'Viewing Homepage';

Remember to take a note of what you entered. Now close and save the file and backtrack to your phpBB root directory and open the following file: includes/constants.php. Within the document find the following line: define('PAGE_GROUPCP', -11);

After the line add new lines to define what phpBB will recognize and also remember to increment the trailing number by 1 for each line you add. For example: define('VIEWING_HOMEPAGE', -12);

Save, Close and once again keep a note of what you entered.

Finally, we're gonna put it all together by configuring files within the admin directory. Once there open index.php and find the following:

Code: Select all
							$location = $lang['Viewing_priv_msgs'];
	$location_url = "index.$phpEx?pane=right";

Please note that the above is found twice in the document and the following will need to therefore be added twice. After this add the following and change the variables according to what you previously entered.

Code: Select all
							$location = $lang['Viewing_Homepage'];
	$location_url = "index.$phpEx?pane=right";

That's basically it except for one thing. Remember right at the beginning when we initiated the $userdata variable on the homepage? Well, replace the red text with VIEWING_HOMEPAGE.

Now every time someone visits your site homepage outside of phpBB, it will be displayed in the Admin Index in the usual fashion.

The process will only display the one message but the process can be repeated multiple times to keep track of visitors ANYWHERE in your site. Cool, eh?

For more information on dynamic websites with phpBB, visit AJ Quick's brilliant tutorial.
Lee McDermott
New User
Posts: 20
Joined: December 14th 2002, 7:50 pm

Postby Thoul » March 31st 2004, 3:11 pm

Here's a minor addition. :) There is code in viewonline.php that is similar to that in admin/index.php.

In that file, look for the following:
Code: Select all
				case PAGE_FAQ:
					$location = $lang['Viewing_FAQ'];
					$location_url = "faq.$phpEx";

After it, add this. You can replace file.php with the filename of the page you're tracking visitors on.
Code: Select all
					$location = $lang['Viewing_Homepage'];
					$location_url = "file.php";
User avatar
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA

Return to phpBB 2: Integrating phpBB With Your Website

Who is online

Users browsing this forum: No registered users and 0 guests