Forum Moderators: coopster

Message Too Old, No Replies

Phrase for every 10 visits

         

Dexie

9:20 am on Feb 2, 2005 (gmt 0)

10+ Year Member



Hi all,

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.

jatar_k

5:08 pm on Feb 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try reformatting your php code and see what happens, like so

<?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 />';
}
?>

Dexie

6:06 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



Many thanks Jatar, will try this.

Sev.

mcibor

10:15 pm on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm glad you found your answer. Was glad to help!

Best regards!
Michal Cibor

This 33 message thread spans 2 pages: 33