...

View Full Version : Echo different messages based on random visitor



this_end_up
11-27-2007, 07:20 PM
Hello,

I would like to combine a few different PHP scripts to create one solution...maybe you guys can help.

I want to start out with a counter script, to count the visits on a single page. Now, instead of "echoing/displaying" a number, I would like it to echo/display a snippet of text based on the number/visitor...

I already have a code to count the visits...it is a "write to" a text file.

But what I want to do is to use the "$fgets" to read the last character/number in the text file. If that number is a five (5) or a zero (0), then I would like to display/echo a message, if it isn't either a 5 or 0, then I would like to display/echo a different message.

So for example: If a visitor lands on the page, and the counter senses that he is visitor number 235, then it will display a message like "great for visiting", but when the next person lands on the page, and is number 236, then a message that will be diplayed will be "thank you."

I have all of the code, such as the counter and the if/then, but I am having trouble with reading the last number/character of the text file. Because the text file will always expand, from single digit for number 1-9 up to say 5 digits for the 10,000 - 99,999, how can I create a script to read the last digit...

Thanks.

Fumigator
11-27-2007, 07:40 PM
Think mathematically. You are really asking for all multiples of 5. If you divide the hit count by 5, then a count that is a multiple of 5 will have a remainder of 0. If it's not a multiple of 5, the remainder will be something other than 0.

The way to test for this in PHP is using the modulus operator (a % sign):



$remainder = $count % 5;
if ($remainder == 0) {
echo "yo";
} else {
echo "not yo";
}

arnyinc
11-27-2007, 08:46 PM
After you get the number with fgets...


$lastdigit = substr($totalhits, -1);

this_end_up
11-27-2007, 11:30 PM
I used "fumigators" solution...it works great. It will also work with other numbers, which is perfect as well.

One other thing is instead of "echo "yo"" is there a way that I could pop open a new window?

Thanks again.


Michael

Pennimus
11-27-2007, 11:38 PM
echo the javascript command you need to pop open a new window...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum