...

View Full Version : Keep Same Variable ALWAYS



As5a5sIn5
05-27-2004, 11:10 PM
Okay..I'm completely new at php, but I am trying to build my new site www.jacostuff.com with php scripts, now I want the main page to show the number of vistors i have... but it will always show one if the variable doesn't ALWAYS stay the same here's my script...

<?php
static $vistors = 0;
$vistors++;
echo "This site has had $vistors vistors";
?>
I'm newb so please be gentle! :o

fimi
05-27-2004, 11:39 PM
Okay..I'm completely new at php, but I am trying to build my new site www.jacostuff.com with php scripts, now I want the main page to show the number of vistors i have... but it will always show one if the variable doesn't ALWAYS stay the same here's my script...

I'm newb so please be gentle! :o

Once the script is executed by ONE visitor then the value of $vistors will completely be lost and on your script you set the variable 0 so you will allways get 1.

You need to save the number of whow many times the page has been opened!
to do that there are two options.
1. using a text file:
$fp = fopen("counter.txt","r");

$count = fread ($fp, filesize ("counter.txt"));

fclose($fp);

$count++;

$fp = fopen("counter.txt","a+");

fputs($fp, $count);

fclose($fp);

echo "Hits: $count";
2. using MySQL Database:USING GD AND MYSQL( GRAPHICAL COUNTER DISPLAY) (http://www.zend.com/zend/tut/counter.php)

As5a5sIn5
05-27-2004, 11:54 PM
hmm thanks...ill try that...I have mySQl but I'm extremely new :)

As5a5sIn5
05-27-2004, 11:55 PM
I mean ill use the text file thing :thumbsup:

fimi
05-27-2004, 11:57 PM
I mean ill use the text file thing :thumbsup:
If you're on a linux server make sure you CHMOD the text file to 777.

Spookster
05-28-2004, 12:51 AM
If you're on a linux server make sure you CHMOD the text file to 777.


That wouldn't be a good idea. You really don't want to give everybody read, write and execute permissions.

fimi
05-28-2004, 01:01 AM
Spookster, the file needs to have write permission, i would look more into the Execute permission.

What would you do to the permissions of the file?

litebearer
05-28-2004, 02:00 AM
just for reference, here is a step by step hit counter script

http://web-bureau.com/modules/free-php-hit-counter-script.php

As5a5sIn5
06-01-2004, 12:17 AM
Thanks Lite Bearer...I read that and I think I understand most of it now...but yet another problem with this ( :o Sorry) After i use the code from that link...still how would i show the vistor amount..im guessing a variable....



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum