September 7th, 2004, 10:15 PM
guys i need to make a hit counter...
and the hit count to appear on a single html....
September 7th, 2004, 10:29 PM
What server do you have access to? Do you have access to a database, and what kind? How experienced are you with PHP, and how far did you get when trying to code it yourself?
BTW, if you really need one there are already tons of those available on the net. You could try hotscripts.com for instance, or good 'ol google. In my oppinion, hit counters don't really add any significant value to a website, though I created a lot of those when I was bored lol.
I could give you code but that wouldn't really teach you anything. IMO, the best way to learn from it is try to do it yourself, and when you can't figure something out ask around about the specific problem you're dealing with. If you just want code, try hotscripts, they usually have such things laying around.
September 7th, 2004, 10:54 PM
I wrote a simple PHP script that can do what he wants, but I fully surrender to Sick Dwarf's elitist questions.
A text file will be created where-ever the file with the code is and it will keep the number of visitors. The echo() statement prints it out and you can use HTML to purrty it up.
$filename = "visitors.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
$fp = fopen('visitors.txt', 'w');
September 8th, 2004, 02:24 AM
Make sure the text file has the correct permissions to be written to if you want to use GW's script.
September 8th, 2004, 04:49 AM
If you have access to a mysql db you might be able to use this.
put this in your index page
$db_host = "localhost";
$db_user = "root";
$db_pass = "password";
$db_name = "yourdb";
what that does is it makes a cookie so that it doesn't increment the hit counter for every single hit, only one hit per 30 minutes per user. That way if someone sits there and refreshes it doesn't increment. But then again they could delete their cookies or not use them at all.
setcookie("hits", "true", (time() + (60*30)));
Lastly put this function in the index page also, the last piece of code as well as this once must be withing the <?php ?> tags.
that actually makes an image with the amount of hits inside it. You must have a table for hits though which you can make like this using the mysql client (make sure you're within the correct db by using "use yourdb")
$connection = mysql_connect($db_host, $db_user, $db_pass) or die("Unable to connect!");
$query = "SELECT hits FROM hits";
$result = mysql_query($query) or die ("Error in query.");
$oldhits = mysql_fetch_assoc($result);
$hits = $oldhits['hits'] + 1;
mysql_query("UPDATE hits SET hits = '".$hits."'") or die ("Error in query.");
$string = $hits;
$im = @imagecreate(50, 25)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 255, 255, 255);
imagestring($im, 5, 5, 5, $string, $text_color);
imagejpeg($im, "/home/user/public_html/images/hits.jpg", 95);
And that in a nutshell is my hit counter. To make that image you must have gd enabled with your php and also maybe libjpeg. I hope you're able to make sense of that and that I didn't leave anything out. I was pulling bits of code from lots of places cause it's all within includes and stuff. Peace.
create table hits (
hits smallint not null
September 8th, 2004, 11:43 AM
ty all... but to exlpain u what i want to do is:....
i have made this Private Servers Status to appear on a png file through fsockopen with php.
and i want somewhere in the image to make appear the counter.
i will try making it with God's Whore way ... looks easier and then if i fail i will try the other ways....
Sick Dwarf... well i have all the control of the server.... mysql4... for the php i know some things... but i don't have enough time to try making the counter by myseld due to school....
September 8th, 2004, 12:01 PM
ok i made it only because you helped me. Without you i wouldn't have made it
ty for the priceless help