SearchWiki:

Contents

Wiki Help

Recent Changes Printable View Page History Edit Page

There are two ways to add the activation code to your web pages.

  1. By simply going to each page and manually adding the activation code, carefully modifying the activation code for each page. This shall be explained first. BBClone will monitor *.php files.
  2. By making your webserver add the code to each page automatically, using a command in a .htaccess file. This is possible if you are running an Apache webserver and can change or add .htaccess files. (If you do have access to .htaccess files, you can make BBClone count htm/html pages as well as php pages, using either the automatic or the manual method of adding the activation code.)

Manually Adding the Activation Code To Every PHP Page

Now that we've tested BBClone and found it working, we can go on to register visits. Simply add the manual activation code like you used for the test.php file to the end of the php files you want to be counted, and change the title (if you're including this line) and change the path to the BBClone installation directory to be correct.

The "traditional" method requires *.php pages. You also need to have permissions to run PHP (of course). If you want to put your code somewhere else the file needs to be included into a *.php file eventually, so the server recognises it and is able to run the PHP interpreter. If BBClone's activation code is placed in a *.html or *.htm file, it will simply be sent to the browser and appear on the web page. The page won't get counted. For BBClone to work with these files, we must say to the server something which amounts to "look through html and htm files for php code and execute any code you find, before sending the web page". This may be done with a command in .htaccess on an Apache webserver (described later on this page). If you don't have access to .htaccess files or are running BBClone on a Windows server, you must use *.php files. (This is as easy as renaming your htm or html files, and then adding the manual activation code to the end of the file.)

Not all code in a PHP file is necessarily PHP code. Sometimes passages of code will be pure html. Each PHP code block is started with "<?php" and ended with "?>". If you want to add the actiavtion code within PHP code, you simply use:

 define("_BBC_PAGE_NAME", "Test");
 define("_BBCLONE_DIR", "bbclone/");
 define("COUNTER", _BBCLONE_DIR."mark_page.php");
 if (is_readable(COUNTER)) include_once(COUNTER);

test activation code within a php block

(or without the page title line, see Testing BBClone for details.) Remember that the relative path in green (bbclone/) has to be from the page you're putting the code into, to the bbclone installation directory.

If you're outside of such a block (and find nothing but html tags) then you need to use the php enclosings so the server knows it has to parse this passage as PHP code.

Automatically Adding the Activation Code To Every PHP Page (Apache webservers only)

If you run an Apache server and are allowed to use .htaccess you can add code to existing .htaccess files, or create new .htaccess files. The commands in .htaccess files affect files in the same directory as the .htaccess and all subdirectories. Using the following commands, your webserver will add the BBClone activation code to *.php before parsing and sending them. (See next section for counting .htm or .html files.)

Create a file "count.php" to contain the BBClone activation code. Create this file and add the following:

 <?php  
define("_BBCLONE_DIR", "/the/path/that/leads/to/bbclone/");
define("COUNTER", _BBCLONE_DIR."mark_page.php");
if (is_readable(COUNTER)) include_once(COUNTER);
?>

count.php

Highlighted in blue is the absolute server path to the BBClone directory. Relative paths are not allowed here. The absolute server path is how the server "sees itself", and does not refer to how someone might browse to the directory in the internet. Notice that the path uses the forward slash (/) and not the backslash (\). If you don't know the absolute path to your BBClone directory you can do the following:

Go to your bbclone directory, open index.php in your favorite editor and add these lines:

 echo  "<?php\n"
      ."define("_BBCLONE_DIR", ""
      .dirname(__FILE__)."/");\n"
      ."define("COUNTER", _BBCLONE_DIR.""
      ."mark_page.php");\n"
      ."if (is_readable(COUNTER)) include_once(COUNTER);\n"
      ."?>\n"; 

determine your absolute path

Upload it to your webserver, point your browser to it, copy and paste the output and save it into a file as "count.php" (to stick with our example). Don't forget to remove the line from index.php afterwards else it will be displayed each time you call your stats.

Now add the following to your chosen .htaccess (to count all pages on your site, add to the .htaccess file above or in your www-root directory):

 <FilesMatch "\.(php)$"> 
 php_value short_open_tag "Off"
 php_value auto_append_file "/the/path/that/leads/to/count.php"
 </FilesMatch>

automatic .php counting

Note that if your BBClone directory is below this .htaccess file in the document tree, visits to the BBClone stats display pages will also be counted, since they are PHP files.

Automatically Adding the Activation Code To Every HTML Page (Apache webservers only)

BBClone is a PHP application, and your server needs to parse the activation code snippet as PHP code. Usually it knows to look through a file for PHP code because a file has a .php extension as part of the filename. But on an Apache webserver, you can tell the server to look through .htm and .html files for PHP code as well, with an extra command in .htaccess.

First create the count.php file as described above.

Then add the following lines to your .htaccess (in addition to the ones above, if you like):

 AddHandler php-script .htm .html  
<FilesMatch "\.(html?)$">
php_value short_open_tag "Off"
php_value auto_append_file "/the/path/that/leads/to/count.php"
</FilesMatch>

automatic .htm(l) counting

The AddHandler line in this code snippet tells your server to parse htm and html files for PHP code, before sending the pages out. (The previously suggested command AddType application/x-httpd-php .htm .html (which works) may be ill advised; more info about this is in the Forum.) The next three lines tell the server to add the activation code contained within count.php to every .html or .htm page. The path to "count.php" needs to be a local absolute server path like the example above (in blue). Remember, an local absolute path is NOT the same as the path you would point your browser to, to see a page. It is the directory structure on the server itself (which you cannot see in a browser). The file "count.php" can be situated anywhere on your webserver, as long as the absolute path points to the correct location.

NOTES:
(Make the first line AddHandler php5-script .htm .html if you're running php5.)
(Try AddHandler application/x-httpd-php .htm .html, if AddHandler php-script .htm .html doesn't work. This was necessary on one server that the author of this text has come across.)
(If you get errors about the php_value command in your server error logs, ask your hosting provider to sort it out. If you still can't use php_value, there is semiautomatic method which requires a little extra work which you can use.)

Now the following will happen: Each time someone calls one of the ".htm" or ".html" pages the code snippet with the counter code will be automatically appended. BBClone will automatically create a page title derived from the file's path which will be used in the page stats.

Next: Configure BBClone using config.php


<< Testing BBClone | Help Index | Configuration Introduction >>

Edit Page - Page History - Printable View - Recent Changes - WikiHelp - SearchWiki
Page last modified on October 05, 2006, at 06:03 PM