See site in english Voir le site en francais
Website skin:
home  download  forum  link  contact

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

Author Topic: OT again: this time, I need a PHP person's help!  (Read 10879 times)

0 Members and 1 Guest are viewing this topic.

Dave Klein

  • Guest
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


Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #1 - 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

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »

Dave Klein

  • Guest
Reply #2 - 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.
         



      








« Last Edit: 28 March 2003, 12:27:27 by Dave Klein »

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #3 - 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

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »

Dave Klein

  • Guest
Reply #4 - 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

« Last Edit: 28 March 2003, 12:27:27 by Dave Klein »

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #5 - 28 March 2003, 11:23:27
"permission denied"  php isn't allowed to write the directory...
server's configuration

mhhhhh ? let me think....

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #6 - 28 March 2003, 11:25:03
I'll look about this reply in few minute

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #7 - 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

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »

Offline canadave

  • Hero Member
  • *****
  • Posts: 531
  • Country: Canada ca
  • Karma: 0
Reply #8 - 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

« Last Edit: 28 March 2003, 12:27:27 by canadave »

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #9 - 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.

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »

Offline canadave

  • Hero Member
  • *****
  • Posts: 531
  • Country: Canada ca
  • Karma: 0
Reply #10 - 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

« Last Edit: 28 March 2003, 12:27:27 by canadave »

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #11 - 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

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »

Offline canadave

  • Hero Member
  • *****
  • Posts: 531
  • Country: Canada ca
  • Karma: 0
Reply #12 - 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)

« Last Edit: 28 March 2003, 12:27:27 by canadave »

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #13 - 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

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #14 - 28 March 2003, 11:44:25
As said none will work into cgi-bin folder
try previous tips

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »

Offline canadave

  • Hero Member
  • *****
  • Posts: 531
  • Country: Canada ca
  • Karma: 0
Reply #15 - 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....

« Last Edit: 28 March 2003, 12:27:27 by canadave »

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #16 - 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 :)

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #17 - 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 :) :) :) :)

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »

Offline canadave

  • Hero Member
  • *****
  • Posts: 531
  • Country: Canada ca
  • Karma: 0
Reply #18 - 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? :)

« Last Edit: 28 March 2003, 12:27:27 by canadave »

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #19 - 28 March 2003, 11:51:17
Let's broke the thread limit counter :)   (its set on 600 if I recall well :up: )

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »

Offline canadave

  • Hero Member
  • *****
  • Posts: 531
  • Country: Canada ca
  • Karma: 0
Reply #20 - 28 March 2003, 11:51:47
HAHAHAHA sure thing....20 and counting!

« Last Edit: 28 March 2003, 12:27:27 by canadave »

Offline canadave

  • Hero Member
  • *****
  • Posts: 531
  • Country: Canada ca
  • Karma: 0
Reply #21 - 28 March 2003, 11:52:24
hell I should just telephone you at this point ROFL

« Last Edit: 28 March 2003, 12:27:27 by canadave »

Offline canadave

  • Hero Member
  • *****
  • Posts: 531
  • Country: Canada ca
  • Karma: 0
Reply #22 - 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.

« Last Edit: 28 March 2003, 12:27:27 by canadave »

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #23 - 28 March 2003, 11:55:35
We are close it seem I see it incrementing

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #24 - 28 March 2003, 11:56:49
Now give me the code that you have on your page to call the counter

« Last Edit: 28 March 2003, 12:27:27 by DanSteph »