Dan's Orbiter page

Orbiter English => Orbiter English => Topic started by: Dave Klein on 28 March 2003, 08:48:37

Title: OT again: this time, I need a PHP person's help!
Post by: Dave Klein on 28 March 2003, 08:48:37
LOL ok, I finally decided to ditch the CGI counter idea for my apfa.ca website.  I finally decided to
just do a PHP script as a counter (as suggested to me by one of the two otherwise unhelpful
people at my webhost).

And lo and behold, it seems to have worked--sort of.  I now have an image file where the counter
should be (good), but it stays at the number "1" (bad).  In other words, the PHP script isn't
incrementing the hit counter at all.  In fact, the script calls for an initial number, which I've set to
1,024, but the webpage still shows "1".  

Anyone out there remotely familiar with PHP want to have a quick look at the source code on
http://www.apfa.ca and tell me where it's fouled up?  It's a small script.

Thanks to anyone who can help!!!!

Cheers,
Dave
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 10:05:07
PHP ? I can help :)

But as the php code is executed before the server send  the page
and translated in html code there is no way we can see the source
so perhaps you can post it here.

Dan
Title: Re: OT again: this time, I need a PHP person's help!
Post by: Dave Klein on 28 March 2003, 10:44:42
Dan, you'd be my hero if you could figure this out!  I'm just posting the whole index.php file
here....there are some smileys where there should be a ")" followed by a ";"....just substitute it
mentally in your head ;)

If there's anything else you need to know to figure this out, please tell me....

Thanks!!!!!!!!
Dave













Welcome to the Alberta Parenting for the Future Association!








   
      

   
   
      
   


         
         Welcome to the

          Alberta Parenting for the Future Association!


         
         

SRC="http://www.apfa.ca/images/PFTFsplashlogo.jpg" border="none" align="absbottom">
         
      



         You are visitor number

         
         

#Abax Hit Counter v1.0, Copyright 2001 By Nathan Dickman, visit http://www.NathanDickman.com/
#This script may be freely distributed providing all copyright headers are kept intact


//Abax Hit Counter configuration//

$datafile="http://www.apfa.ca/cgi-bin/apfa.dat";                 //filename for counter datafile
$counterstyle = "image";                  //enter text for text,image for images, or invisible for none
$textcountlength = 4;                     //length of counter in digits if using text option          
$font = "Arial, Helvetica, sans-serif";   //font face style if using text counter
$fontsize = "2";                          //font size if using text counter
$fontcolour = "#999999";                  //font colour use html colour codes
$imagedirectory = "http://www.apfa.ca/cgi-bin/images/";  //directory or http location to images
NOTE: use trailing slash
$imagesext = ".gif";                      //file extension for images e.g. .gif .jpg .png              
$initialvalue = 1024;

//MAIN CODE//

if (!file_exists($datafile)) {
   $file = fopen($datafile,"w+");
   fwrite ($file,$initialvalue);
   fclose ($file);
  }
else  {

   $file = fopen($datafile,"r+");
   $hitcount = fread($file,filesize($datafile));
   fclose ($file);

 };



$hitcount++;

$file = fopen($datafile,"w+") ;
fwrite ($file,$hitcount);


if ($counterstyle != "invisible") {

if ($counterstyle == "text")  {

   echo ""
   .sprintf("%0"."$textcountlength"."d",$hitcount)."
";
  }
else  {

   $longstr = strlen($hitcount);
   for ($x=0; $x < $longstr; $x++)  {

$image = substr($hitcount,$x,1);

echo "\"$image\"";

       }
  }
}

?>   
         

         


         This site is best viewed at

          1024x768 resolution or higher.
         



      







Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 11:13:19
replace the line:
$datafile="http://www.apfa.ca/cgi-bin/apfa.dat"; //filename for counter datafile

with:

$datafile="apfa.dat"; //filename for counter datafile

I suggest you  use the text version while it's faster to load and don't forget:

-this version will count all hit not only unique visitor (ie: if you refresh the page 5 time it count 5 hit)
-no count will be made if the counter is not on the page that visitor view
(ie: if you have the counter on the start page and the visitor have a direct link to your menu page
no count will be made)
-if you put this counter on each page ONE visitor may give you 1-25 hit

if it work I can give you my counter (unique visitor, visitor this day, month , years, online, customizable about what value you want to display, (I can do that for you))(and it's really simple to install. (you just need to put a small code on every page)

))) <- just to close all the parenthesis opened (programmer's mania :)

Dan
Title: Re: OT again: this time, I need a PHP person's help!
Post by: Dave Klein on 28 March 2003, 11:15:34
Hmmmm....didn't work...check out the site now, after I made the change and took out the "http://"
part of the apfa.dat path! :0

Dave
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 11:23:27
"permission denied"  php isn't allowed to write the directory...
server's configuration

mhhhhh ? let me think....
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 11:25:03
I'll look about this reply in few minute
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 11:37:03
Of course, "cgi-bin" folder are usually protected in writting by a client,
this is logical , if not, everyone would be able to modify cgi program
(imagine the hole in the security)

1- create a directory "counter"  in your root
2- move the counter.php in this directory and the whole images's directory also
3- modify the script line:
$imagedirectory = "http://www.apfa.ca/cgi-bin/images/"; //directory or http location to images

with
$imagedirectory = "http://www.apfa.ca/counter/images/"; //directory or http location to
images
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 11:37:08
Thanks Dan....

For what it's worth, the webhost guys said that the permissions on this (a Windows server) are
set to wide open--no restrictions.  And it's strange that the "no permissions" error only comes
when I have the filename set to anything but the path + the dat file, as I had in the original php
file.  Doesn't that indicate that the filename setting is correct, and something else is causing the
counter not to increment?

If you have a good counter script, sure, toss it this way (via email?)  I feel crazy for spending this
much time (and this much of YOUR time) on a silly counter...surely there's got to be an easier way!  
If you have one, I'm all ears.....

Dave
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 11:38:29
anytime I program EVERYTHING I don't loose my time :)

protection are perhaps wide open but I doubt this is the case about cgi-bin folder
this would be way too dangerous.
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 11:40:23
I wrote that last response before YOUR last response.  I just tried what you suggested...still no
luck :(  The cgi-bin directory was created by ME, of all people!  This particular webhost seems to be
one where they just give you a /web/ directory and it's up to you to create all the directories you
need for things like CGI and such.

My offer to try out your simpler script still stands ;)  All I need is a basic counter so that I can track
how many people visit the front page.

Thanks!
Dave
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 11:40:57
I should implement a chat room on my site :)

And the counter work fine on my side it's really a permission denied problem
try the tips given previously.

Dan
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 11:43:12
Yes, it would seem we DO need a chat room ;)

The counter works fine on your side?  What do you mean?  Are you saying that if you
click "Refresh" the counter advances?  Mine's stuck on "1" no matter what.

I'm about ready to give up on this script, if you've got a better one I'll try that.  And I have tried everything you've suggested in this post =D

Dave



Post Edited (03-28-03 11:43)
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 11:43:27
cgi-bin folder are usually recognized by server (if this one is well configured)

And we'll have a look about a more complex counter when we will be
able to make this one work (because we should test write permission else no counter
will ever work)

Dan
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 11:44:25
As said none will work into cgi-bin folder
try previous tips
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 11:46:03
This cgi-bin folder was created by me.  When I asked the webhost originally, "How do I get a cgi-
bin directory on this server to run CGI scripts, which you say you support?", his answer was, "Just
create it."  And he said the permissions were wide open--no restrictions.

I think the permissions problems we're seeing were because the path was not a full path, so it
didn't know where to write...at least that's my amateur opinion? :)

I can email you the password and login if you want to have a look....
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 11:46:21
The counter work fine on my side while I test it in "localhost"
(mean I run a local server on my computer)
So it's really a permission problem
(and no counter will work without permission)

Again try previous tips it should work :)
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 11:48:23
if you want but I don't have ftp access here at work
(I use another tips to update my page from here)

cgi-bin are ALWAYS dedicated for cgi script and they are usually
recognised by the server and permission are denied automatically
for client writing.

tryyyyyyyyyyyyyyyyyyyy the previous tips :) :) :) :)
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 11:50:22
LOL I *DID* try the previous tips, man!!! lolol

It's not working.  

I renamed the cgi-bin directory to counter, and here are the permissions on that directory as I look
at it in my FTP client:

-rwxrw-rw-

Does that mean anything to you, O php guru? :)
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 11:51:17
Let's broke the thread limit counter :)   (its set on 600 if I recall well :up: )
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 11:51:47
HAHAHAHA sure thing....20 and counting!
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 11:52:24
hell I should just telephone you at this point ROFL
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 11:54:57
I can't even change the permissions.  It's not a UNIX server.  I tried to do a CHMOD anyway to full
open (RWX for everybody!) but it didn't work.  Of course.  It's a LOSEdows server.
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 11:55:35
We are close it seem I see it incrementing
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 11:56:49
Now give me the code that you have on your page to call the counter
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 11:56:58
Yeah I just noticed that too!!!!  apfa.dat is showing "10", but the graphic image on the webpage
is still at "1".
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 11:57:27

#Abax Hit Counter v1.0, Copyright 2001 By Nathan Dickman, visit http://www.NathanDickman.com/
#This script may be freely distributed providing all copyright headers are kept intact


//Abax Hit Counter configuration//

$datafile="http://www.apfa.ca/counter/apfa.dat";                 //filename for counter datafile
$counterstyle = "image";                  //enter text for text,image for images, or invisible for none
$textcountlength = 4;                     //length of counter in digits if using text option          
$font = "Arial, Helvetica, sans-serif";   //font face style if using text counter
$fontsize = "2";                          //font size if using text counter
$fontcolour = "#999999";                  //font colour use html colour codes
$imagedirectory = "http://www.apfa.ca/counter/images/";  //directory or http location to images
NOTE: use trailing slash
$imagesext = ".gif";                      //file extension for images e.g. .gif .jpg .png              
$initialvalue = 1024;

//MAIN CODE//

if (!file_exists($datafile)) {
   $file = fopen($datafile,"w+");
   fwrite ($file,$initialvalue);
   fclose ($file);
  }
else  {

   $file = fopen($datafile,"r+");
   $hitcount = fread($file,filesize($datafile));
   fclose ($file);

 };



$hitcount++;

$file = fopen($datafile,"w+");
fwrite ($file,$hitcount);


if ($counterstyle != "invisible") {

if ($counterstyle == "text")  {

   echo ""
   .sprintf("%0"."$textcountlength"."d",$hitcount)."
";
  }
else  {

   $longstr = strlen($hitcount);
   for ($x=0; $x < $longstr; $x++)  {

$image = substr($hitcount,$x,1);

echo "\"$image\"";

       }
  }
}

?>
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 11:58:16
Notice, though, that the variable $initialvalue is set to 1024, so apfa.dat should theoretically be
starting out at 1024.  But it's not.
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 12:00:23
replace:
$datafile="http://www.apfa.ca/counter/apfa.dat"; //filename for counter datafile

with

$datafile="apfa.dat"; //filename for counter datafile
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 12:01:03
OK....I tried that earlier, but I'll do it again.  Two seconds, please!
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 12:01:57
Done.  Changed it to simply apfa.dat, and now it's screwed up again.
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 12:07:17
then try replacing by :

$datafile="counter\/apfa.dat"; //filename for counter datafile
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 12:08:03
And :) , it work !

(no ?)
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 12:09:16
WHAAA?  counter\/apfa.dat???

OK, I'll try it *scratching head doubtfully*....but I dno't think it'll work........
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 12:10:07
OH MY GOD!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 12:10:12
HYEAAAAAAA
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 12:11:05
Now you just need to edit the abfa.dat file to give it 1024 as a value and you will have your 1024
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 12:12:01
OK now that is just F****** CRAZY!!!!!!!!!!!!!!!!!!!!!!!!!

What the hell??????????????

I've never seen the slashes mixed like that for ANYTHING!!!!!!!

And not to nitpick...but it's STILL not working right....the initialvalue variable seems to have NO
effect....

But I'm NOT COMPLAINING!!!!!  THANK YOU THANK YOU THANK YOU!!!!!!
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 12:12:08
don't be worry if it pass frome 40 to 60 or 80 I click also on it :)
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 12:14:21
curious the initial value doesn't seem to work here also
a small bug but that's not a big problem
edit manually the abfa.dat file with notepad
and replace the ** value with 1024

(or click on your page 1024 time :)  )
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 12:14:30
Oh man....I give up *sigh*

I am not worthy to be in your presence, sir!!!!!  You are a god.  How the hell you figured that out,
I'll never know...and I'm GOOD with computers....

It's 4:15am here, and I'm totally out of it....I will just thank you ONE more time (THANK YOU!) and
now I'm going to go to bed and celebrate by dreaming of web counters all night ;)

THanks again Dan!  As we used to say in New York City, "You da MAN!"

Dave

p.s. does this mean the 600-post thread limit will remain unchallenged? ;)
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 12:15:28
Pouf 1026 :)
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 12:16:14
Yeah...."pouf" because I edited the apfa.dat file like you said ;)
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 12:16:35
have a good night sir :zzz:
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 12:17:17
tomorrow we will give you *REAL* counter
(no headeach don't worry)
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 12:17:38
I am looking at that part of the script you had me correct...and I swear to god, it STILL doesn't
look right.  It looks like it should be broken, and yet it's not.  Why this is, I cannot say *shaking
head in wonderment*
Title: Re: OT again: this time, I need a PHP person's help!
Post by: canadave on 28 March 2003, 12:18:02
sounds good man...thanks again!  g'night ;)

Dave
Title: Re: OT again: this time, I need a PHP person's help!
Post by: DanSteph on 28 March 2003, 12:27:27
Debugging in real time by a forum thread that was a first experience for me,  Thank to you :)

Now you just need to count sheep to have a nice sleep

1 sheep
2 sheep
3 sheep
4.. :zzz: