We've noticed that you've been inactive for over 10 minute(s). We've stopped running the Shoutbox due to your inactivity. If you are back again, please click the I'm Back button below.
(18 April 2013 - 09:35 PM)however, why this mixing of capital letters in the middle of your text?
Replying to Easy Visitor Counter
Topic Summary
Posted 16 May 2011 - 12:08 PM
to VandanaEasy Visitor CounterUse $_SERVER['REMOTE_ADDR'] to check and compare the ip address. If you know the ip address of the so called your enemy (bloked ip ) if he traced then use header to redirect some other site-reply by Manoj Updhyay
Posted 19 February 2010 - 06:31 AM
How to block the internal ip address in hit count of the website?Easy Visitor CounterHow to block the internal ip address in hit count of the website?-question by vandana
Yes I think that a database would be a better idea as it requires a password to access and is less work to use than by writing to a file each time. This is because unless you have specific permissions set, anyone can read that file and that may not be a good thing.
With a database you can do so much more though, such as IP logging, browser (user-agent) identification, etc. This may or may not be useful but to most people it should be because it helps efficiently target their audience in some cases.
That seems like a lot of work to count the number of visitors. Also how safe is it? I get a little worried when you try to edit actual files rather then using a database. This is how I would count visitors using a database:
<?php
//Update
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$row = mysql_fetch_array(mysql_query("SELECT * FROM info WHERE ID='1'") or die(mysql_error()));
$count = $row['count']+1;
$result = mysql_query("UPDATE info SET count='$count' WHERE ID='1'") or die(mysql_error());
//Display
echo 'Visitors: <font color="#FF6600">'.$count.'</font>.';
?>
This method is great and very secure unless you don't have MySQL access. Otherwise your script would be the only option and would work good as long as you made sure your server only allowed editing of that file only and only from the server itself (not an external server/hacker).
Your script is still good to know though because when you get into more advanced things you might need to actually save a file to the server (for example when someone is installing your open source code on their server).