Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Can't Put in Visitor Counter  (Read 6955 times)

0 Members and 1 Guest are viewing this topic.

pftq

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 111
Can't Put in Visitor Counter
« on: August 04, 2006, 01:24:54 am »

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.

Code: [Select]
<?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);
?>
« Last Edit: August 04, 2006, 11:31:03 pm by Nibbler »
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Can't Put in Visitor Counter
« Reply #1 on: August 04, 2006, 08:30:16 am »

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
Code: [Select]
$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.
Logged

pftq

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 111
Re: Can't Put in Visitor Counter
« Reply #2 on: August 04, 2006, 09:36:00 am »

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.
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Can't Put in Visitor Counter
« Reply #3 on: August 04, 2006, 09:48:55 am »

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
Code: [Select]
$count = dirname(__FILE__) . "/../easycounter/EasyCounter.txt"; (and the subsequent lines) to
Code: [Select]
$count = "/foo/bar/whatever/public_html/easycounter/EasyCounter.txt"; As suggested above: this is NOT a Coppermine issue.

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.
Whoa calm down for a sec.
I'm not upset at all, just posting my thoughts. Therefor, no need to calm down ;)
Logged

pftq

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 111
Re: Can't Put in Visitor Counter
« Reply #4 on: August 04, 2006, 09:54:01 am »

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." ;)
Logged

pftq

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 111
Re: Can't Put in Visitor Counter
« Reply #5 on: August 04, 2006, 10:00:38 am »

Nope no luck.  Same result. :(
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Can't Put in Visitor Counter
« Reply #6 on: August 04, 2006, 10:16:03 am »

Code: [Select]
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

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 111
Re: Can't Put in Visitor Counter
« Reply #7 on: August 04, 2006, 10:23:14 am »

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.
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Can't Put in Visitor Counter
« Reply #8 on: August 04, 2006, 10:25:13 am »

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.
Logged

pftq

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 111
Re: Can't Put in Visitor Counter
« Reply #9 on: August 04, 2006, 10:29:32 am »

I put in the field:

../pq/frame.php

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

Sami

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 3686
  • BMossavari
    • My Project
Re: Can't Put in Visitor Counter
« Reply #10 on: August 04, 2006, 10:33:59 am »

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

pftq

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 111
Re: Can't Put in Visitor Counter
« Reply #11 on: August 04, 2006, 10:40:43 am »

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

Nibbler

  • Guest
Re: Can't Put in Visitor Counter
« Reply #12 on: August 04, 2006, 12:34:48 pm »

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

Code: [Select]
global $ipfile,$duration;
 global $activenum, $actfile, $highact;
 global $count,$aktip;
Logged

pftq

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 111
Re: Can't Put in Visitor Counter
« Reply #13 on: August 04, 2006, 01:59:38 pm »

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
« Last Edit: August 04, 2006, 02:22:04 pm by pftq »
Logged

Nibbler

  • Guest
Re: Can't Put in Visitor Counter
« Reply #14 on: August 04, 2006, 03:09:13 pm »

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

pftq

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 111
Re: Can't Put in Visitor Counter
« Reply #15 on: August 04, 2006, 11:13:22 pm »

Ah ok. Thanks :D
Logged
Pages: [1]   Go Up
 

Page created in 0.026 seconds with 20 queries.