I have encountered a new issue in statistics.php file.

My statistics counters do not increment. I am running on IIS and the define at the top

define('DRUPAL_ROOT', substr($_SERVER['SCRIPT_FILENAME'], 0, strpos($_SERVER['SCRIPT_FILENAME'], '/modules/statistics/statistics.php')));

is not platform directory separator aware.

It should be something like:

PHP_OS == "Windows" || PHP_OS == "WINNT" ?
  define('DRUPAL_ROOT', substr($_SERVER['SCRIPT_FILENAME'], 0, strpos($_SERVER['SCRIPT_FILENAME'], '\\modules\\statistics\\statistics.php'))) :
  define('DRUPAL_ROOT', substr($_SERVER['SCRIPT_FILENAME'], 0, strpos($_SERVER['SCRIPT_FILENAME'], '/modules/statistics/statistics.php')))
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein’s picture

Version: 7.31 » 7.x-dev
Status: Active » Needs review

There's a patch from @david_garcia based on an idea from @mikeytown2 at #1209532-247: Count node views via AJAX in the statistics module that fixes this in a way that shouldn't involve checking the operating system - let's review that.

fgm’s picture

Why not use the standard DIRECTORY_SEPARATOR constant instead of doing manual replacements with '/' and '\\' like this ?

david_garcia’s picture

david_garcia’s picture

@fgm Yes we could use the DIRECTORY_SEPARATOR, but we need a new patch then.

Timothy.Siford’s picture

Version: 7.x-dev » 7.39
Status: Needs review » Reviewed & tested by the community

+1. Tested on Drupal 7.39, IIS, SQL Server 2014, PHP 5.6.0.

cilefen’s picture

Version: 7.39 » 7.x-dev
Status: Reviewed & tested by the community » Needs work

This needs work for #4 or a decision not to go with DIRECTORY_SEPARATOR.

david_garcia’s picture

Why not use the standard DIRECTORY_SEPARATOR constant instead of doing manual replacements with '/' and '\\' like this

Assuming that you don't know what the input will be like, this is much more robust, because it normalizes whatever results from calling realpath($_SERVER['SCRIPT_FILENAME']).

So I vote that we go with the current no brain melter patch unchanged.

vanessakovalsky’s picture

Project: Drupal core » Statistics
Version: 7.x-dev » 1.x-dev
Component: statistics.module » Code

Need to check and use constant DIRECTORY_SEPARATOR in statistics.php file

vanessakovalsky’s picture

Project: Statistics » Drupal core
Version: 1.x-dev » 10.3.x-dev
Component: Code » statistics.module

Still need to fix on D10 on statistics.php line "chdir("../../..")