Can't Put in Visitor Counter Can't Put in Visitor Counter
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Can't Put in Visitor Counter

Started by pftq, August 04, 2006, 01:24:54 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

pftq

Hi I have the following code on all pages of my site (so that they get counted onto the visitor counter) but it doesn't seem to work on the gallery.  I put it in as a heading php file.  The banner shows up fine but it doesn't seem to get counted into the visitor counter.

The paths should all be correct because dirname(__FILE__) refers to the php file that all of my pages include.

The counter doesn't display anything - but it should be writing to a file who's viewing the gallery, which it doesn't appear to be doing.  It works fine on all my other pages - so it seems to be something that the gallery has.

Here's the code.  I'm using EasyCounter from www.wingnut.net.ms  with a several modifications I made to it.

<?php
// #################################################################//
// #  script by WingNut                        www.wingnut.net.ms  #//
// #                                                               #//
// #  this script has been published under the gnu public license  #//
// #  you may edit the script but never delete this comment! thx.  #//
// #################################################################//
// --begin editable region

// database files
$count dirname(__FILE__) . "/../easycounter/EasyCounter.txt"
$ipfile dirname(__FILE__) . "/../easycounter/EasyCounter_IPs.txt";
$actfile dirname(__FILE__) . "/../easycounter/EasyCounter_Active.txt";

// duration of IP lock in minutes
$duration 15

// language (english, german)
$language "english";

// --end editable region
//##################################################################//
// Do not change anything by now unless you know what you are doing!

$phpversion phpversion();
if (
$phpversion 4.1){
  global 
$HTTP_SERVER_VARS;
  
$aktip $HTTP_SERVER_VARS['REMOTE_ADDR'];
  if ((
$aktip == "127.0.0.1") && ($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'] != ""))
  {
    
$aktip $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'];
  }
}
else{
  
$aktip $_SERVER['REMOTE_ADDR'];
  if ((
$aktip=="127.0.0.1")&&($_SERVER['HTTP_X_FORWARDED_FOR']!=""))
  {
    
$aktip $_SERVER['HTTP_X_FORWARDED_FOR'];
  }
}

function 
checkip($ip)
{
  global 
$ipfile,$duration;
  
$timestamp time();
  
$file file($ipfile);
  
$fileloc $_SERVER['PHP_SELF'];
  
$iphandle fopen($ipfile,"w+");
  if(
sizeof($file)==0)
  {
    
fputs($iphandle"$ip|$timestamp|$fileloc\n");
zaehlen();
  }
  else
  { 
    
$got false;
    foreach (
$file as $line
    {
      
$exp_line explode("|"$line);
  if(($exp_line[1]+ 60*$duration) > $timestamp) {
    if($exp_line[0] == $ip) {
  $got true;
  fputs($iphandle"$ip|$timestamp|$fileloc\n"); 
}
else {
   
      fputs($iphandle"$line");
}
      }
    }
if($got == false)
{
fputs($iphandle"$ip|$timestamp|$fileloc\n"); 
    zaehlen();
}
  }
  
fclose($iphandle);
  
  
//Highest Active
  
global $activenum$actfile$highact;
  
$activefile file($actfile);
  
$actread fopen($actfile"r");
  
$highact fread($actreadfilesize($actfile));
  
fclose($actread);
  
$actcount fopen($actfile"w+");
  
$activenum=sizeof($file);
  if(
sizeof($activefile)==0)
  {
    
fputs($actcount"$activenum");
  }
  else
  {
  if(
$highact<=$activenum)
    {
      
fputs($actcount"$activenum");
    }
    else
    {
      
fputs($actcount"$highact");
     }
  }
  
fclose($actcount);
}       



// print functions
  
global $count,$aktip;
  
checkip($aktip);
  
$handle fopen($count,"r");
  while(
$inhalt fgetcsv($handle1024"|"))
  {
    
$text "$inhalt[0]";
  }
  
fclose ($handle);
?>

Joachim Müller

1) Use the code button in the future (the one with the hash sign on it), it makes your posting more readable - I modified your posting accordingly.
2) Where did you insert that piece of code (into what file)?
3) Post a link to your gallery
4) The line $count = dirname(__FILE__) . "/../easycounter/EasyCounter.txt"; is of course plain wrong: the leading slash indicates that you're going to use an absolute path, root folder. The following two dots indicate "one level up", which is of course wrong, as you can't go up from the root folder.

Bottom line: you have to understand how paths work. Make sure that the paths point to the proper places, and that the folders and files you specify in your script actually exist and are writable. This is however not related to coppermine at all, but just a matter of your PHP coding skills.

pftq

1) Oops sorry about that - thanks for correcting :)

2) "I put it in as a heading php file. "

3) K here it is

4) ... Whoa calm down for a sec.

First off

dirname(__FILE__) . "/../easycounter/EasyCounter.txt";

It's not plain wrong.  Note I used dirname(__FILE__) in addition to the second part.  Therefore the leading slash and following .. will not go up above the root folder.  It goes up from the location of the included file. :)

I understand fine how paths work.  They do in fact point to proper places - the files and folders exist and are very well writable.  As I said in my first post "It works fine on all my other pages - so it seems to be something that the gallery has."

I'm not saying it's Coppermine's <fault>.  I'm just askin for what might be conflicting.

Joachim Müller

Hm, dirname would be something like "/foo/bar/whatever". Subsequently, the resulting path would be "/foo/bar/whatever/.../easycounter/EasyCounter.txt", which is just an invalid path in my book. You can't use the double dots in the middle of a path, but only at the start. Why not use absolute paths without the need to fiddle with dirname and then going up. Will work everywhere.
Find out the absolute path (using phpinfo()). It might be something like "/foo/bar/whatever/public_html/gallery". Then change$count = dirname(__FILE__) . "/../easycounter/EasyCounter.txt"; (and the subsequent lines) to$count = "/foo/bar/whatever/public_html/easycounter/EasyCounter.txt"; As suggested above: this is NOT a Coppermine issue.

Quote from: pftq on August 04, 2006, 09:36:00 AM
2) "I put it in as a heading php file. "
Be a little more detailed. Test if the include is done correctly by echoing something in your include to test that the include itself works.

Joachim

P.S.
Quote from: pftq on August 04, 2006, 09:36:00 AMWhoa calm down for a sec.
I'm not upset at all, just posting my thoughts. Therefor, no need to calm down ;)

pftq

Well it seems to work fine on all my other pages - so seems kinda weird there'd be problems with that - but I'll try it thanks. :)

The include works. "The banner shows up fine but it doesn't seem to get counted into the visitor counter." ;)

pftq


Stramm

2) Where did you insert that piece of code (into what file)?
you say heading ... not sure what you mean. What coppermine file you used to include your php code. Please tell the filename and say how you included the code.

What banner shows up fine... and I can't spot any counter on your site.

pftq

Ah ok sorry for the confusion.

Heading - as in the include heading feature in the Admin > Config > Themes.  I included http://pftq.com/pq/frame.php that I include on all my pages.

The banner/navigation at the top of the gallery (pftq, Life, Creations, 42)

The counter is on the main page www.pftq.com .  The code is so that visitors who don't come through the main page also get counted.

Joachim Müller

as suggested, be more detailed - what exactly did you enter into the "custom header" field in coppermine's config. Post a link to the include file itself as well.

pftq

I put in the field:

../pq/frame.php

the file I want to include is http://pftq.com/pq/frame.php

Sami

then dirname(__FILE__) will bring back something like that :
Inetpub\wwwroot\pq
is this correct path ....?
‍I don't answer to PM with support question
Please post your issue to related board

pftq

Yea it returns the path of the pq/frame.php without the / and frame.php

Nibbler

I don't think the path is a problem. Add this code into the top of the file to resolve the variable scope.


global $ipfile,$duration;
global $activenum, $actfile, $highact;
global $count,$aktip;

pftq

#13
Hey thanks - that got the gallery to write to the files.  Works now I think.. (still don't get why it worked on all else but just not the gallery ??? but ah well)

Few things though.

- $_SERVER['PHP_SELF'] is supposed to return the url of the current page (not included file).  For the gallery, instead of returning gallery/index.php, it returns index.php.

Not sure what to make of that.  Guess gallery is considered the root for the gallery section of the site.  Ah well I'll just use somethin else.

Thanks

Nibbler

We redefine $_SERVER['PHP_SELF']. You can global and then use $ORIGINAL_PHP_SELF instead.

pftq