User Tools

Site Tools



Once the script installation is complete you will need to add the script to your page(s). To do this you will need at least one file to add the script to. You may already have this file existing somewhere on your site, perhaps it's an article that you have written or some other useful information. If you don't then you will need to create one now. Once you know which file to add the script to, move onto the steps below. The file should ideally be a PHP file. If it's a HTML file then read the 'HTML Pages' section below.

In the package you downloaded, there is an example.php file which you can look at.

Step One

The first step for integration is to add the following to the very first line of the file. It is necessary for session-dependant features to work. By first line, this means even above the <!DOCTYPE html> and <html> lines.


Step Two

Next you need to add the following line inside the HTML head tag of the file. It declares the UTF-8 charset which means that foreign characters can be displayed. If you already have this line then there is no need to add it again. If you have the 'ISO-8859-1' charset tag, or any other charset tag, please remove it and replace it with this UTF-8 one.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

Step Three

The last part is the code to actually display the comments and the comment form. This should be added somewhere in your HTML body tag, wherever you want the comments to be shown.

The identifier can contain any value. Just make sure that it's unique to each page that you add the script to.

The reference should be a short descriptive term of the page. It is shown to your visitors. Using the heading of the page is a good idea.

The path stores the server path (not the URL path) from the file to the /upload/ folder. If your file is in the root of your website, you can leave this line alone. If in a directory then add ../ to the start so it is “../upload/”. If in a directory in a directory it should be “../../upload/” and so on.

There is never any need to edit the other lines.

$cmtx_identifier = '1';
$cmtx_reference = 'Page One';
$cmtx_path = 'upload/';
require $cmtx_path . 'includes/commentics.php'; //don't edit this line

Many Pages

If you want to add the script to many pages then you won't want to do this manually. Fortunately, as of Commentics v1.4, there are several built-in features to make this easier. By entering keywords into the $cmtx_identifier and $cmtx_reference variables the script can perform actions to replace these keywords with dynamic information.

Please note that these keywords should only be used as a last resort. If you have many pages then there's a good chance that you have a database-driven website where each page already has a unique ID which you can supply to Commentics. Using this ID is always best.

The keywords that can be entered for the Identifier value are:

  • cmtx_title: Retrieves the <title> value from inside the head tag of the page. (requires cURL or fopen)
  • cmtx_h1: Retrieves the <h1> value from inside the body tag of the page. (requires cURL or fopen)
  • cmtx_filename: Retrieves the filename of the page.
  • cmtx_url: Retrieves the URL of the page. (see the URL Parameters section below)
  • cmtx_reference: Sets the same value as the reference.

The keywords that can be entered for the Reference value are:

  • cmtx_title: Retrieves the <title> value from inside the head tag of the page. (requires cURL or fopen)
  • cmtx_h1: Retrieves the <h1> value from inside the body tag of the page. (requires cURL or fopen)
  • cmtx_filename: Retrieves the filename of the page.
  • cmtx_url: Retrieves the URL of the page. (see the URL Parameters section below)
  • cmtx_identifier: Sets the same value as the identifier.

Of course, you can also supply your own dynamic information such as $cmtx_identifier = $_GET['name'];

URL Parameters

Sometimes a website URL will contain query parameters that determine the content of the page, such as

URLs might also contain extra query parameters that are not important, such as

To remove unwanted parameters, you can add a variable called 'cmtx_parameters' to the top of your integration code. For its value, simply list your important parameters separated by a comma and then the script will remove any parameters not in the list. For example:

$cmtx_parameters = 'id';
$cmtx_identifier = 'cmtx_url';
$cmtx_reference = 'Page One';
$cmtx_path = 'upload/';
require $cmtx_path . 'includes/commentics.php'; //don't edit this line

An example list could be $cmtx_parameters = 'id,category,language';

By leaving the $cmtx_parameters value empty or by typing “none” the script will remove all URL query parameters.

Note that this only works in conjunction with the cmtx_url keyword.

HTML Pages

Most of the code for Commentics is written in PHP, meaning that for integration a normal HTML file won't work. Fortunately there are (at least) a couple of options available.

  • The easiest solution is to add a line of code to a .htaccess file which will tell your server to execute any PHP code found in your HTML file(s) as such. With this method you don't need to alter your HTML file(s) at all. The .htaccess file can be in the same directory as the HTML file(s) or in any directory above it. It's usually best to put it in the root of your website. If you already have a .htaccess file there then just add it to that one. You can find an example of a .htaccess file inside the /upload/ folder. The line of code is:
AddHandler application/x-httpd-php5 .html .htm .shtml
# If your host is 'Go Daddy', or the above does not work, try this line instead
AddHandler x-httpd-php5-cgi .html .htm .shtml
  • Another option is to change the file extension from HTML to PHP. This can be done with your FTP application (e.g. FileZilla). Depending on how many files you have, this may take a while. A common concern with this method is the negative effect that it can have on your search engine listings. You can avoid this issue with the use of a permanent (301) redirect. This informs the search engines that the location of your page has changed so that they can update your URL and keep any page ranking. This process can take some time so it is important to keep the redirect alive for a period of time. Every page will need its own redirect. Again, this solution uses .htaccess and the line of code is as follows:
Redirect 301 /somepage.html

Login Details

If your site uses a login system, you may want to pass some of this information to Commentics so that your visitors won't need to fill in the form. Fortunately, as of Commentics v2.0, this is possible by adding a few lines to the top of your integration code.

$cmtx_set_name_value = '';
$cmtx_set_email_value = '';
$cmtx_set_website_value = '';
$cmtx_set_town_value = '';
$cmtx_set_country_value = '';

After adding the above lines, you may want to disable or hide the fields to make it quicker and simpler for your visitors to complete the form. As of Commentics v2.4, this can be done by changing the settings in Layout → Form → States.

Set Topic

The topic, (displayed at the top right of the comments section), is retrieved from the page's reference. If you would like to change the topic, but not the page reference, simply add this line to the top of your integration code.

$cmtx_set_topic = '';


While the integration should go as intended if you follow the instructions correctly, there are certain errors that may appear.

  1. You may get a “headers already sent” error message. If so, try this FAQ:
  2. You might see unwanted symbols on your pages such as . This is because your website's template files responsible for displaying output may not be encoded correctly. To fix this open the files in Notepad++ and go to “Format → Convert to UTF-8 without BOM”.
  3. If you can't see any .htaccess files on your server, with FileZilla, go to “Server → Force showing hidden files”.
documentation/integration.txt · Last modified: 2015/05/08 23:06 by steven