Forum Moderators: coopster
Michal referred me here - thanks Michal.
I'm trying to present the visitor to the website with a simple 2 line phrase. The phrase would be shown to the person who visits the home page every 10th time, so *not* for the person's 10th visit, it's for every 10th visit generally. Can anyone please let me know how I can do this please?
My hosts server can take cgi.
Any help appreciated.
Sev.
<?php
$counterfile = 'counter.txt';
$phrasesfile = 'phrases.txt';
$multiple = 10;
// Read in the value, trim off any newlines, and
// convert it to an integer,
// just in case:
$text = intval(trim(@file_get_contents($counterfile)));
// Update the file with the old value plus this hit:
@file_put_contents($counterfile, $text += 1);
// Is the value a multiple of 10?
if ($text && $text % $multiple == 0) {
// Read the phrases file into an array:
$file = @file($phrasesfile);
print 'Hey! It\'s visit #' . $text . '!<br />';
// Grab a random phrase from the file read in as an array:
print $file[rand(0, count($file) - 1)] . '<br />';
}
?>