dennylin93 Posted November 20, 2006 Share Posted November 20, 2006 I need to create an invisible counter for my website with php or Flash, but I don't know how. Could anyone please teach me? I don't have access to any databases though. Thanks in advance. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 20, 2006 Share Posted November 20, 2006 There are a few steps. The first one is to check for and set a cookie, so that you don't count the same person twice. Start here for that:http://www.php.net/manual/en/features.cookies.phpYou will want to check the cookie when someone shows up, and if it is not there you will want to give them a cookie and update a text file with the count. So, the second step is to open the file, read it, and write it.You will want to use this function to read the counter file:http://www.php.net/manual/en/function.file-get-contents.phpLike this: <?php $count = intval(file_get_contents("/path/to/counter.txt"));?> And then use fwrite to write the new value back. This modified example is from the reference page for fwrite: <?php$filename = 'test.txt';// Let's make sure the file exists and is writable first.if (is_writable($filename)) { if (!$handle = fopen($filename, 'wb')) { echo "Cannot open file ($filename)"; exit; } if (fwrite($handle, $count + 1) === FALSE) { echo "Cannot write to file ($filename)"; exit; } fclose($handle);} else { echo "The file $filename is not writable";}?> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now