Page 1 of 1
Question related to count the guests in a website
Posted: Mon Jan 26, 2009 4:53 am
by g_p
Hello, i'm using the following code in order to count the guests in my website
Code: Select all
$guest = 0;
$ip = $_SERVER["REMOTE_ADDR"];
$arr_guest = array("$guest" => $ip); // Store information in an array
$guest++; // Increment $guest
echo "Print array of guests .<br />";
$i = $guest;
for ($i = 0 ; $i <= ($guest - 1); $i++) {
echo " $i : $arr_guest[$i]" . "<br />";
}
With the previous code, whenever someone visits my web page, the $guest becomes zero.
I mean that $guest loses the previous value it has and starts from zero all the time!
What shall i do in order to keep the value of $guest?
Thanks in advance!

Re: Question related to count the guests in a website
Posted: Mon Jan 26, 2009 6:39 am
by Mark Baker
g_p wrote:Hello, i'm using the following code in order to count the guests in my website
With the previous code, whenever someone visits my web page, the $guest becomes zero.
I mean that $guest loses the previous value it has and starts from zero all the time!
What shall i do in order to keep the value of $guest?
It does. That's the way it works.
If you want to retain your list of guests, then you have to "persist" the array, eithr storing the information in a database, or a file, or even shared memory (if you're using APC or similar)
Re: Question related to count the guests in a website
Posted: Mon Jan 26, 2009 9:14 am
by g_p
Mark Baker wrote:g_p wrote:Hello, i'm using the following code in order to count the guests in my website
With the previous code, whenever someone visits my web page, the $guest becomes zero.
I mean that $guest loses the previous value it has and starts from zero all the time!
What shall i do in order to keep the value of $guest?
It does. That's the way it works.
If you want to retain your list of guests, then you have to "persist" the array, eithr storing the information in a database, or a file, or even shared memory (if you're using APC or similar)
Hi, thanks for replying, When you say to store it in a file, like txt?
I mean does php support this? I may store information from php to a simple file?
Also, i searched google for APC but i didn't understand what it is, may you please tell me?
May you please post me a very simple example of php where sm writes something from php to a file?
thanks in advance!

Re: Question related to count the guests in a website
Posted: Mon Jan 26, 2009 9:18 am
by mattpointblank
Re: Question related to count the guests in a website
Posted: Mon Jan 26, 2009 9:32 am
by g_p
Thanks

Re: Question related to count the guests in a website
Posted: Mon Jan 26, 2009 10:03 am
by papa
True story!
